我在website上设置了一个Fancybox图片库,并在每个图片弹出框中集成了社交分享。我遇到的问题是,当有人去推文时,网站的URL没有附加到预先填充的Twitter消息。
我不确定我做错了什么,因为我遵循了这个JSFiddle教程,介绍了如何将社交按钮与Fancybox集成,而且代码与我的代码几乎相同......
这是社交按钮的JS:
$('.fancybox-buttons')
.attr('rel', 'gallery')
.fancybox({
openEffect : 'none',
closeEffect : 'none',
prevEffect : 'none',
nextEffect : 'none',
beforeShow: function () {
if (this.title) {
// New line
this.title += '<br />';
// Add tweet button
this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-text="Amazing work by artist Tegan Whitesel!" data-count="none" data-url="' + this.href + '">Tweet</a>';
// Add FaceBook like button
this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&layout=button_count&show_faces=true&width=500&action=like&font&colorscheme=light&height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:23px;" allowTransparency="true"></iframe>';
// Add Pinterest "Pin It" button
this.title += '<a href="http://pinterest.com/pin/create/button/?url=http://www.teganwhitesel.com/#painting&media=http%3A%2F%2Fwww.teganwhitesel.com%2Fpainting%2Fbeginnings-3_b.jpg&description=Tegan%20Whitesel%20-%20Beginnings%20III" class="pin-it-button" count-layout="none"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>';
}
},
afterShow: function () {
// Render tweet button
twttr.widgets.load();
},
helpers: {
title: {
type: 'inside'
}, //<-- add a comma to separate the following option
buttons: {} //<-- add this for buttons
},
closeBtn: true, // you will use the buttons now
arrows: true
});
以下是我网站index.html
<header>
部分中的其他脚本代码:
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>