sharejs 使用文档
gitee:gitee.com/ywsckj/shar…
代码在 sharejs使用/components/sharejs
分享信息设置
在
head里面设置分享信息,如果无国外分享,只要主要标签即可。分享标签生成网站:metatags.io/
<!-- 主要标签 --> <title>Meta Tags — Preview, Edit and Generate</title> <meta name="title" content="Meta Tags — Preview, Edit and Generate"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <!-- Open Graph / Facebook --> <meta property="og:type" content="website"> <meta property="og:url" content="http://www.lconnect.com.mm"> <meta property="og:title" content="Meta Tags — Preview, Edit and Generate"> <meta property="og:description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <meta property="og:image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <!-- Twitter --> <meta property="twitter:card" content="summary_large_image"> <meta property="twitter:url" content="http://www.lconnect.com.mm"> <meta property="twitter:title" content="Meta Tags — Preview, Edit and Generate"> <meta property="twitter:description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <meta property="twitter:image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg">
分享平台
| 分享平台配置参数 | 描述 |
|---|---|
| Viber | Viber |
| 电子邮箱 | |
| 微信 | |
| fanfou | 饭否 |
| 领英 | |
| vk | Vkontakte |
| stumbleupon | StumbleUpon |
| yummly | Yummly |
| yahoomail | YahooMail |
| wordpress | WordPress |
| trello | Trello |
| surfingbird | Surfingbird |
| snapchat | Snapchat |
| skype | Skype |
| outlook | outlook |
| meneame | meneame |
| mailru | mailru |
| livejournal | livejournal |
| iorbix | iorbix |
| instapaper | instapaper |
| diaspora | diaspora |
| buffer | buffer |
| kindleit | kindleit |
| evernote | evernote |
| qzone | QQ空间 |
| sinaweibo | 新浪微博 |
| txQQ | 腾讯QQ |
| txPYW | 腾讯朋友网 |
| diandian | 点点网 |
| douban | 豆瓣网 |
| 脸书 | |
| 推特 | |
| gmail | 谷歌邮箱 |
| googleplus | googleplus |
| tumblr | Tumblr |
| refind | refind |
| kooapp | kooapp |
| kakao | kakao |
| hackernews | hackernews |
| digg | digg |
| blogger | blogger |
| googlebookmarks | googlebookmarks |
| odnoklassniki | odnoklassniki |
| delicious | delicious |
| renren | 人人网 |
| line | LINE |
分享示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<!-- 主要元标签 -->
<title>分享示例</title>
<meta name="title" content="标题">
<meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg">
<meta name="keywords" content="关键字">
<meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="http://www.lconnect.com.mm">
<meta property="og:title" content="Meta Tags — Preview, Edit and Generate">
<meta property="og:description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">
<meta property="og:image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="http://www.lconnect.com.mm">
<meta property="twitter:title" content="Meta Tags — Preview, Edit and Generate">
<meta property="twitter:description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">
<meta property="twitter:image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg">
<link rel="stylesheet" href="components/sharejs/css/sharejs.css">
<script src="components/sharejs/js/sharejs.js"></script>
</head>
<body>
<button onclick="showMsg('显示复制提示层')">显示复制提示层</button>
<button onclick="showWxTips()">显示微信提示层</button>
<button onclick="showPop()">显示弹窗层</button>
<button onclick="copyText('显示复制提示层')">复制文本</button>
<button onclick="shareEvent('txQQ')">单独分享</button>
<div class="shareBox" data-url="分享链接1" data-title="分享标题1"></div>
<div><div class="shareBox" data-url="分享链接2" data-title="分享标题2"></div></div>
<div><div class="shareBox" data-url="分享链接3" data-title="分享标题3"></div></div>
<script>
var webShare=new sharejs({
lang: 'zh',//语言
popCode:true,//是否显示二维码
copyShare:true,//弹窗复制内容分享
dom: '.shareBox',//分享触发元素
sites: ['qzone', 'txQQ', 'sinaweibo', 'wechat', 'viber','whatsApp'],//默认展示的分享
text: false,//是否显示分享文字
list: true,//是否是分享列表
});
</script>
</body>
</html>
参数配置
| 参数及默认值 | 说明 |
|---|---|
| lang: 'zh', | //语言,string,中文:zh,英文:en,缅甸语:mm |
| msgConfig:null, | //自定义复制提示层配置,object |
| msgTime: 1500, | //提示框关闭时间,number,设置为0时不自动关闭 |
| wxTipsConfig:null, | //自定义微信提示层配置,object |
| popConfig:null, | //自定义弹窗层配置,object |
| popCode:true, | //是否显示二维码,Boolean |
| popShare:false, | //是否显示弹窗分享列表,Boolean,不存在列表分享 |
| copyLink: true, | //弹窗复制链接,Boolean |
| copyShare:false, | //弹窗复制内容分享,Boolean |
| codeConfig: null, | //自定义二维码配置,object |
| fontFamily: 'shareFont', | //字体图标名称,string |
| shareContent:null, | //自定义分享内容配置,object |
| shareConfig: null, | //自定义分享配置,object |
| shareTipsConfig:null, | //自定义分享提示层配置,object |
| shareListConfig: null, | //自定义分享列表配置,object |
| dom: '', | //分享触发元素,string |
| sites: [], | //分享平台配置,Array,详细见自定义分享平台 |
| initBefore: null, | //初始化之前执行函数,function(options){} |
| initAfter: null, | //初始化之后执行函数,function(options){} |
| type: 'list', | //分享类型,string, list:为列表类型, btn:为按钮类型, fixedLeft为固定左边(此类型无列表分享,未完善), fixedRight为固定右边(此类型无列表分享,未完善) |
| text: false, | //是否显示分享文字,Boolean |
| title: true, | //是否显示鼠标经过标题文字,Boolean |
| btnEvent: 'mouseenter', | //pc按钮类型触发事件,详细事件见鼠标事件 |
| btnEventMb: 'click', | //手机端按钮类型触发事件,详细事件见鼠标事件 |
| event: 'click', | //一般类型触发事件,详细事件见鼠标事件 |
| theme: '', | //主题样式,string,theme1,theme2,theme3 |
| list: false, | //是否是分享列表,Boolean data-url分享链接、 data-title分享标题、 data-desc分享描述、 data-img分享图片 |
| download: false, | //下载链接 |
| pop: false, | //分享弹窗 |
| wxPop: false, | //微信浏览器分享弹窗 |
| exe: false, | //应用跳转 |
分享列表设置
分享列表需要在调用元素设置分享信息
<div class="shareBox" data-url="分享链接" data-title="分享标题" data-desc="分享描述" data-img="分享图片"></div>示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <!-- 主要元标签 --> <title>分享列表</title> <meta name="title" content="标题"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <link rel="stylesheet" href="components/sharejs/css/sharejs.css"> <script src="components/sharejs/js/sharejs.js"></script> </head> <body> <div> <div class="shareBox" data-url="分享链接1" data-title="分享标题1" data-desc="分享描述1" data-img="分享图片1"></div> <div class="shareBox" data-url="分享链接2" data-title="分享标题2" data-desc="分享描述2" data-img="分享图片2"></div> <div class="shareBox" data-url="分享链接3" data-title="分享标题3" data-desc="分享描述3" data-img="分享图片3"></div> </div> <script> var webShare = new sharejs({ dom: '.shareBox', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 list: true, //是否是分享列表 }); </script> </body> </html>
自定义分享内容配置
var share=new sharejs({ dom:'.ewm', shareContent:{ url: '',//分享地址 title: '',//分享标题 description: '',//分享描述 image: '',//分享图片 } });示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <!-- 主要元标签 --> <title>自定义分享内容配置</title> <meta name="title" content="标题"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <link rel="stylesheet" href="components/sharejs/css/sharejs.css"> <script src="components/sharejs/js/sharejs.js"></script> </head> <body> <div> <div class="shareBox"></div> </div> <script> var webShare = new sharejs({ dom: '.shareBox', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 shareContent:{ url: '分享地址',//分享地址 title: '分享标题',//分享标题 description: '分享描述',//分享描述 image: '分享图片',//分享图片 } }); </script> </body> </html>
自定义二维码配置
var share=new sharejs({ dom:'.ewm', codeConfig:{ width: 150,//二维码宽度 height: 150,//二维码高度 color: '#000',//二维码颜色 bgColor: '#fff',//二维码背景颜色 } });示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <!-- 主要元标签 --> <title>自定义二维码配置</title> <meta name="title" content="标题"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <link rel="stylesheet" href="components/sharejs/css/sharejs.css"> <script src="components/sharejs/js/sharejs.js"></script> </head> <body> <div> <div class="shareBox"></div> </div> <script> var webShare = new sharejs({ dom: '.shareBox', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 codeConfig:{ width: 150,//二维码宽度 height: 150,//二维码高度 color: '#f00',//二维码颜色 bgColor: '#fff',//二维码背景颜色 } }); </script> </body> </html>
自定义弹窗层配置
var share=new sharejs({
dom:'.ewm',
popConfig:{
fontFamily:'shareFont',
showClass:'show',
boxClass:'sharejs_popMask',
conClass:'sharejs_popCon',
headerClass:'sharejs_popHeader',
titleClass:'sharejs_title',
closeIconClass:'sharejs_close',
closeIcon:'icon_shareClose',
bodyClass:'sharejs_popBody',
codeBoxClass:'sharejs_codeBox',
codeConClass:'sharejs_codeCon',
codeConId:'sharejs_codeCon',
shareContentClass:'sharejs_shareContent',
popShareClass:'sharejs_popShare',
footerClass:'sharejs_popFooter',
linkBoxClass:'sharejs_linkBox',
linkConClass:'sharejs_linkCon',
linkBtnClass:'sharejs_linkBtn',
linkValClass:'sharejs_linkVal',
linkInputClass:'sharejs_linkInput',
linkIconClass:'sharejs_linkIcon',
linkIcon:'icon_shareLink',
linkBtn2Class:'sharejs_linkBtn2',
title:{
'zh':'扫一扫分享',
'en':'Sweep 1 Sweep Share',
'mm':'ဥပမာ ၊',
},
copyText:{
'zh':'复制',
'en':'Copy',
'mm':'မိတ္တူပါ',
},
copyText2:{
'zh':'已复制',
'en':'Copied',
'mm':'ကူးယူပါ',
},
}
});
自定义微信提示层配置
var share=new sharejs({
dom:'.ewm',
wxTipsConfig:{
fontFamily:'shareFont',
showClass:'show',
boxClass:'sharejs_wxMask',
textClass:'sharejs_wxTipsText',
iconClass:'sharejs_wxTipsIcon',
icon:'icon_shareBtn9',
text:{
'zh':'请点击右上角将它发送给指定朋友或分享到朋友圈',
'en':'Please click on the top right corner to send it to designated friends or share it to friends circle',
'mm':'မိတ်ဆွေ များသို့ ပေးပို့ရန် (သို့) သို့မဟုတ် မိတ်ဆွေ များကို ဝေမျှခြင်းကို ပြုလုပ်ပါ။',
}
}
});
自定义复制提示层配置
var share=new sharejs({
dom:'.ewm',
msgConfig:{
fontFamily:'shareFont',
showClass:'show',
boxClass:'sharejs_msgBox',
conClass:'sharejs_msgCon',
closeTimeClass:'timeFalse',
closeClass:'sharejs_msgClose',
closeIcon:'icon_shareClose',
textClass:'sharejs_msgText',
text:{
'zh':'复制成功',
'en':'Copy succeeded',
'mm':'မိတ္တူကို ကောင်းမွန်စွာ ပြီးပြီ',
}
}
});
自定义分享列表配置
var share=new sharejs({
dom:'.ewm',
shareListConfig: {
listClass: 'sharejs_list',
itemClass: 'sharejs_item',
conClass: 'sharejs_con',
iconClass: 'sharejs_icon',
textClass: 'sharejs_text',
fontFamily: '',
btnClass: 'sharejs_btn',
btnIconClass: 'icon_shareBtn1',
}
});
自定义分享提示层配置
var share=new sharejs({
dom:'.ewm',
shareTipsConfig:{
boxClass:'sharejs_tips',
showClass:'show',
},
});
自定义分享配置
var share = new sharejs({ dom: '.ewm', shareConfig: { '分享名称': { fontFamily: ' ',//字体图标名称 logo: ' ',//字体图标class color: ' ',//颜色 initBefore: null, //分享前事件 initAfter: null, //分享后事件 url: '',//官网url web_url: '',//网页url exe_url: '',//应用url download_url: '',//下载链接 pop: false, //弹窗分享 download: false, //应用下载 text: { 'zh': '中文', 'en': '英文标题', 'mm': '缅甸语标题', }, } } });示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <!-- 主要元标签 --> <title>自定义分享配置</title> <meta name="title" content="标题"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <link rel="stylesheet" href="components/sharejs/css/sharejs.css"> <script src="components/sharejs/js/sharejs.js"></script> </head> <body> <div> <div class="shareBox"></div> </div> <script> var webShare = new sharejs({ dom: '.shareBox', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 shareConfig: { 'sinaweibo': { // fontFamily: '',//字体图标名称 // logo: '',//字体图标class initBefore: function(){ console.log('分享前事件'); }, //分享前事件 initAfter: function(){ console.log('分享后事件'); }, //分享后事件 url: '',//官网 web_url: 'https://www.baidu.com/', exe_url: '',//应用url download_url: '',//下载链接 pop: false, //弹窗分享 download: false, //应用下载 text: { 'zh': '自定义分享配置中文', 'en': '自定义分享配置英文标题', 'mm': '自定义分享配置缅甸语标题', }, } } }); </script> </body> </html>
分享类型
- type: 'list',:为列表类型(默认)
- type: 'btn',:为按钮类型
列表类型
new sharejs({ dom: '.shareBox1', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 type: 'list',//分享类型 });按钮类型
new sharejs({ dom: '.shareBox2', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 type: 'btn',//分享类型 });
分享设备
- system:'pc',为电脑
- system:'mb',为手机
电脑
new sharejs({ dom: '.shareBox2', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 system:'pc',// 分享设备 type: 'btn',//分享类型 });手机
new sharejs({ dom: '.shareBox2', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 system:'mb',// 分享设备 type: 'btn',//分享类型 });
按钮主题
可以直接使用主题或自己根据参数配置
- theme: 'theme1',
- theme: 'theme2',
- theme: 'theme3',
- theme: 'theme4',
默认
new sharejs({
dom: '.shareBox', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
});
theme1
new sharejs({
dom: '.shareBox1', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
theme: 'theme1', //按钮主题
});
theme2
new sharejs({
dom: '.shareBox2', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
theme: 'theme2', //按钮主题
});
theme3
new sharejs({
dom: '.shareBox3', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
theme: 'theme3', //按钮主题
});
theme4
new sharejs({
dom: '.shareBox4', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
theme: 'theme4', //按钮主题
});
搭配参数
new sharejs({ dom: '.shareBox4', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme3', //按钮主题 text:true,//是否显示分享文字 });示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <!-- 主要元标签 --> <title>按钮主题</title> <meta name="title" content="标题"> <meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg"> <meta name="keywords" content="关键字"> <meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!"> <link rel="stylesheet" href="components/sharejs/css/sharejs.css"> <script src="components/sharejs/js/sharejs.js"></script> </head> <body> <div> <div class="shareBox"></div> <div class="shareBox1"></div> <div class="shareBox2"></div> <div class="shareBox3"></div> <div class="shareBox4"></div> <div class="shareBox5"></div> </div> <script> new sharejs({ dom: '.shareBox', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 }); new sharejs({ dom: '.shareBox1', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme1', //按钮主题 }); new sharejs({ dom: '.shareBox2', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme2', //按钮主题 }); new sharejs({ dom: '.shareBox3', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme3', //按钮主题 }); new sharejs({ dom: '.shareBox4', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme3', //按钮主题 text: true, //是否显示分享文字 }); new sharejs({ dom: '.shareBox4', //分享触发元素 sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享 theme: 'theme4', //按钮主题 }); </script> </body> </html>
鼠标事件
| 事件 | 描述 |
|---|---|
| click | 当用户点击某个对象时调用的事件句柄。 |
| contextmenu | 在用户点击鼠标右键打开上下文菜单时触发 |
| dblclick | 当用户双击某个对象时调用的事件句柄。 |
| mousedown | 鼠标按钮被按下。 |
| mouseenter | 当鼠标指针移动到元素上时触发。 |
| mouseleave | 当鼠标指针移出元素时触发 |
| mousemove | 鼠标被移动。 |
| mouseover | 鼠标移到某元素之上。 |
| mouseout | 鼠标从某元素移开。 |
| mouseup | 鼠标按键被松开。 |
回调函数
初始化前
var share=new sharejs({
dom:'.ewm',
initBefore:function(){
console.log('初始化前');
},
});
初始化后
var share=new sharejs({
dom:'.ewm',
initAfter:function(){
console.log('初始化后');
},
});
示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<!-- 主要元标签 -->
<title>回调函数</title>
<meta name="title" content="标题">
<meta name="image" content="http://file.clovepy-gz.sitepapa.com/img/img1.jpg">
<meta name="keywords" content="关键字">
<meta name="description"
content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">
<link rel="stylesheet" href="components/sharejs/css/sharejs.css">
<script src="components/sharejs/js/sharejs.js"></script>
</head>
<body>
<div>
<div class="shareBox"></div>
</div>
<script>
var webShare = new sharejs({
dom: '.shareBox', //分享触发元素
sites: ['wechat', 'qzone', 'txQQ', 'sinaweibo'], //展示的分享
initBefore: function() {
console.log('初始化前');
},
initAfter: function() {
console.log('初始化后');
},
});
</script>
</body>
</html>
公共方法函数
多级对象合并
assignObjects(obj1,obj2,obj3)
多级对象内嵌数组合并
mergeObjects(obj1,obj2,obj3)
创建元素
createElement(options)createElement({ tag:'div',//标签名称 setAttribute:[{ //自定义设置属性 name: '', key: '' }], children:[ createElement({tag:'div'}) ],//添加子级 })
阻止冒泡事件
stopTrue(event)
判断微信浏览器和其他浏览器
isBrowser()
判断是PC端和移动端
isSystem()
选中div文本
selectText(element)selectText(document.body)
单独分享事件
shareEvent(shareName,shareContent,options)shareEvent('txQQ')