Jquery fancybox上的社交按钮
我想将这个脚本集成到我之前存在的FancyBox配置中(我使用wordpress的FancyBox插件,所以我只能编辑FancyBox配置的一部分) 这是我的配置:Jquery fancybox上的社交按钮,jquery,facebook,wordpress,fancybox,social,Jquery,Facebook,Wordpress,Fancybox,Social,我想将这个脚本集成到我之前存在的FancyBox配置中(我使用wordpress的FancyBox插件,所以我只能编辑FancyBox配置的一部分) 这是我的配置: <script type="text/javascript"> jQuery(function(){ jQuery.fn.getTitle = function() { // Copy the title of every IMG tag and add it to its parent A so that f
<script type="text/javascript">
jQuery(function(){
jQuery.fn.getTitle = function() { // Copy the title of every IMG tag and add it to its parent A so that fancybox can show titles
var arr = jQuery("a.fancybox");
jQuery.each(arr, function() {
var title = jQuery(this).children("img").attr("title");
jQuery(this).attr('title',title);
})
}
// Supported file extensions
var thumbnails = jQuery("a:has(img)").not(".nolightbox").filter( function() { return /\.(jpe?g|png|gif|bmp)$/i.test(jQuery(this).attr('href')) });
thumbnails.addClass("fancybox").attr("rel","fancybox").getTitle();
jQuery("a.fancybox").fancybox({
'cyclic': false,
'autoScale': true,
'padding': 10,
'opacity': true,
'speedIn': 500,
'speedOut': 500,
'changeSpeed': 300,
'overlayShow': true,
'overlayOpacity': "0.5",
'overlayColor': "#000000",
'titleShow': true,
'titlePosition': 'inside',
'enableEscapeButton': true,
'showCloseButton': true,
'showNavArrows': true,
'hideOnOverlayClick': true,
'hideOnContentClick': false,
'width': 560,
'height': 340,
'transitionIn': "fade",
'transitionOut': "fade",
'centerOnScroll': true
});
/* I can edit this part */
})
</script>
jQuery(函数(){
jQuery.fn.getTitle=function(){//复制每个IMG标记的标题,并将其添加到其父级A中,以便fancybox可以显示标题
var arr=jQuery(“a.fancybox”);
每个(arr,function(){
var title=jQuery(this).children(“img”).attr(“title”);
jQuery(this).attr('title',title);
})
}
//支持的文件扩展名
var thumbnails=jQuery(“a:has(img)”).not(.nolightbox”).filter(函数(){return/\(jpe?g | png | gif | bmp)$/i.test(jQuery(this.attr('href')));
thumbnails.addClass(“fancybox”).attr(“rel”,“fancybox”).getTitle();
jQuery(“a.fancybox”).fancybox({
“循环”:错误,
“自动缩放”:正确,
“填充”:10,
“不透明”:正确,
“speedIn”:500,
“加速输出”:500,
“更改速度”:300,
“叠加显示”:正确,
“产能过剩”:“0.5”,
“套色”:“#000000”,
“标题秀”:没错,
“标题位置”:“内部”,
“enableEscapeButton”:true,
“showCloseButton”:true,
“showNavArrows”:正确,
“HideonOvercyclick”:对,
“hideOnContentClick”:false,
“宽度”:560,
身高:340,
“transitionIn”:“淡入淡出”,
“transitionOut”:“淡入淡出”,
“centerOnScroll”:真
});
/*我可以编辑这个部分*/
})
我不懂Jaavascript,所以我不知道如何集成这个脚本
谢谢你的帮助 只需将下面提到的代码添加到fancybox的最后一个属性之后,即 “'centerOnScroll':true”“put”“并粘贴以下代码
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-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>';
}
},
afterShow: function() {
// Render tweet button
twttr.widgets.load();
},
helpers : {
title : {
type: 'inside'
}
}
beforeShow:函数(){
如果(本标题){
//新线
this.title+='
';
//添加tweet按钮
此.title+='';
//添加类似FaceBook的按钮
此.title+='';
}
},
afterShow:function(){
//渲染tweet按钮
twttr.widgets.load();
},
助手:{
标题:{
类型:“内部”
}
}
希望这有助于解决您的问题。我只能将代码放在签名为/*的部分中,我可以编辑此部分*/如果使用fancybox v2.x,此答案中的代码可能会起作用,但WordPress的任何fancybox插件都使用v1.3.4,因为它不适用于wp,但作为如何在标题中添加按钮或其他内容的说明,仍然很有价值。谢谢,我要用这个!