【问题标题】:Social buttons on fancyboxfancybox 上的社交按钮
【发布时间】:2013-05-04 12:37:04
【问题描述】:

我想将此脚本http://jsfiddle.net/G5TC3/ 集成到我现有的 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 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>

我不懂 Jaavascript 所以我不知道如何集成这个脚本 感谢您的帮助!

【问题讨论】:

    标签: jquery facebook wordpress fancybox social


    【解决方案1】:

    只需在 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 + '&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;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'
            }
        } 
    

    希望此帮助并解决您的问题。

    【讨论】:

    • 我只能在 /* 签名的部分放代码 */
    • 如果使用fancybox v2.x,此答案中的代码可能会起作用,但WordPress的任何fancybox插件都使用v1.3.4
    • 并不是真正的问题答案,因为它不适用于 wp,但作为如何向标题添加按钮或其他任何内容的说明仍然很有价值。谢谢,我会用这个!
    猜你喜欢
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    相关资源
    最近更新 更多