1

I want integrate this script http://jsfiddle.net/G5TC3/ into my pre existent configuration of FancyBox (I use Fancybox plugin for wordpress, so I can edit only a part of the configuration of fancybox)

This is my configuration:

    <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>

I don't understand Jaavascript so I don't know how to integrate this script Thanks for the help!

4

1 回答 1

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'
        }
    } 

希望这有助于并解决您的问题。

于 2013-05-04T13:06:06.847 回答