朋友圈分享並更換為自己的圖片
阿新 • • 發佈:2021-01-29
技術標籤:htmlcssjavascript
利用原生js實現分享朋友圈並更改為自己想要的圖片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no" >
<title>百度分享-分享到朋友圈及qq</title>
<style type="text/css">
.share-div .bdsharebuttonbox .common-size {
width: 30px;
height: 30px;
}
.share-div .bdsharebuttonbox .bds_weixin {
background: url("../img/wechat-icon.png" ) no-repeat center;
background-size: 30px 30px;
}
</style>
</head>
<body>
<div class="share-div">
<div class="bdsharebuttonbox">
<div>
<div class="share-img">
<a href= "#" data-cmd="weixin" title="分享到微信" class="common-size bds_weixin"></a>
</div>
<div class="share-img">
<a href="#" data-cmd="tsina" title="分享到新浪微博" class="common-size bds_tsina"></a>
</div>
<div class="share-img">
<a title="分享到Facebook" data-cmd="fbook" class="common-size bshare-facebook bds_fbook"></a>
</div>
<div class="share-img">
<a title="分享到Twitter" data-cmd="twi" class="common-size bshare-twitter bds_twi"></a>
</div>
</div>
</div>
</div>
<script>
window._bd_share_config = {
"common": {
"bdSnsKey": {},
"bdText": "",
"bdMini": "2",
"bdMiniList": false,
"bdPic": "",
"bdStyle": "0",
"bdSize": "16"
},
"share": {},
"selectShare": {"bdContainerClass": null, "bdSelectMiniList": ["weixin", "tsina", "fbook","twi"]}
};
with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
</script>
</body>
</html>
實現效果如圖所示:
- 更改為自己想要實現的圖片,需在class為bdsharebuttonbox的div外,在進行一層div包裹,以此覆蓋其原本的樣式