发布时间:2020/04/23 作者:天马行空 阅读(1511)
插件下载地址:https://github.com/overtrue/share.js
使用方法:
<div class="share-component" data-sites="qq,wechat,qzone,weibo,douban">分享:</div> <link rel="stylesheet" href="/www/plugin/share/css/share.min.css"> <script src="/www/plugin/share/js/social-share.min.js"></script>
自定义配置:
url : '', // 网址,默认使用 window.location.href source : '', // 来源(QQ空间会用到), 默认读取head标签:<meta name="site" content="http://overtrue" /> title : '', // 标题,默认读取 document.title 或者 <meta name="title" content="share.js" /> origin : '', // 分享 @ 相关 twitter 账号 description : '', // 描述, 默认读取head标签:<meta name="description" content="PHP弱类型的实现原理分析" /> image : '', // 图片, 默认取网页中第一个img标签 sites : ['qzone', 'qq', 'weibo','wechat', 'douban'], // 启用的站点 disabled : ['google', 'facebook', 'twitter'], // 禁用的站点 wechatQrcodeTitle : '微信扫一扫:分享', // 微信二维码提示文字 wechatQrcodeHelper : '<p>微信里点“发现”,扫一下</p><p>二维码便可将本文分享至朋友圈。</p>'
示例代码:
var $config = { title : '234', description : '123', wechatQrcodeTitle : "微信扫一扫:分享", // 微信二维码提示文字 wechatQrcodeHelper : '<p>微信里点“发现”,扫一下</p><p>二维码便可将本文分享至朋友圈。</p>', };socialShare('.social-share-cs', $config);
上选项均可通过标签 data-xxx 来设置,驼峰转为中横线,如wechatQrcodeHelper 的data标签为data-wechat-qrcode-helper
禁用 google、twitter、facebook 并设置分享的描述
<div class="share-component" data-disabled="google,twitter,facebook" data-description="Share.js - 一键分享到微博,QQ空间,腾讯微博,人人,豆瓣"></div>
设置微信二维码标题
<div class="social-share" data-wechat-qrcode-title="请打开微信扫一扫"></div>
针对特定站点使用不同的属性(title, url, description,image...)
<div class="social-share" data-weibo-title="这个标题只有的分享到微博时有用,其它标题为全局标题" data-qq-title="分享到QQ时用此标题"></div>