分享 share

share HTML 加copy

1
2
3
4
5
6
7
8
9
10
<div class="addtoany_list">
<div class="share-button"><em></em><span>分享至</span></div>
<div class="social-share" data-initialized="true">
<a class="social-share-icon icon-weibo" href="#">&nbsp;</a>
<a class="social-share-icon icon-wechat" href="#">&nbsp;</a>
<a class="social-share-icon icon-copy" href="javascript:">&nbsp;</a>
<div class="copy-success">复制成功</div>
<div class="copy-error">请手动"复制"</div>
</div>
</div>

share CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@import url("https://nspro.dev.ciandt.cn/sites/all/themes/custom/npro_master/css/share.min.css?pkoxsv");
css文件夹同级放入fonts文件夹,icon字用的

.social-share {
float: right;
margin-bottom: 20px;
}
.social-share .social-share-icon {
font-size: 0 !important;
margin: 0 4px;
}
.social-share .social-share-icon:before {
font-size: 20px;
}

share JS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script type="text/javascript" src="js/social-share.min.js"></script>
<script type="text/javascript" src="js/clipboard.min.js"></script>
function shareWechat() {
if ($('.addtoany_list').length){
var $config = {
wechatQrcodeTitle : "微信扫一扫:分享",
wechatQrcodeHelper : '<p>在微信中扫描二维码后</p><p>点击右上角的 ··· 分享</p>'
};
}
}

function noClipboard () {
$('.copy-error').fadeIn('slow');
setTimeout(function(){
$('.copy-error').fadeOut('slow');
},2000);
}

function shareCopyUrl(){
var clipBoardContent = window.location.href;
if(ClipboardJS.isSupported()) {//copy: clipboard Plugin
var clipboard = new ClipboardJS('.icon-copy', {
text: function() {
return clipBoardContent;
}
});

clipboard.on('success', function(e) {
$('.copy-success').fadeIn('slow');
setTimeout(function(){
$('.copy-success').fadeOut('slow');
},2000);
});

clipboard.on('error', function(e) {
noClipboard();
});
}
else {
$('.icon-copy').click(function(event) {
noClipboard();
});
}
}

$(document).ready(function() {
shareCopyUrl();
});

More info: demo,share.