gitmyhub

share.js

JavaScript ★ 3.8k updated 1y ago

一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点等

A minimal JavaScript library that adds social sharing buttons to any web page with one HTML element and two files, supporting Chinese and Western platforms like WeChat, Weibo, Twitter, Facebook, and LinkedIn.

JavaScriptCSSnpmRequireJSsetup: easycomplexity 1/5

Share.js is a JavaScript library that adds social sharing buttons to web pages. You drop a single HTML element onto your page, include one CSS file and one JavaScript file, and the library automatically generates clickable icons that let visitors share the current page to platforms like Weibo, WeChat, QQ Space, QQ Friends, Tencent Weibo, Douban, Facebook, Twitter, LinkedIn, and Google+.

The setup is minimal. You add a div with the class social-share, link the bundled stylesheet and script, and the buttons appear without any further initialization. If you want to control which platforms show up, you pass a configuration object listing the ones to enable or disable. You can also override the shared URL, title, description, and image rather than letting the library read them from the page automatically.

Configuration can be done two ways: through a JavaScript object passed to the socialShare function, or through data attributes on the HTML element itself. For WeChat specifically, the library shows a QR code popup because WeChat does not support a standard share URL scheme, and you can customize the text shown in that popup.

The library works with or without jQuery and supports loading via RequireJS for projects that use module bundlers. You can also disable the auto-generated icons entirely and supply your own anchor elements, which the library then wires up with the correct share links.

The README includes a note that the project has not been actively maintained for some time, and that sharing fundamentally works by building a URL with content parameters for each platform. For highly custom requirements, the author suggests implementing the links directly. The license is MIT.

Where it fits