jquery - 在同一页面上使用 jquery gallery 两次

标签 jquery css

我正在使用一个简单的 jquery 库 ( JQuery Hover Effect Image Gallery For eCommerce ),它运行完美。

其中一个页面有两个画廊,我想使用这个脚本。我精通 Javascript 来扩展脚本以支持两个画廊,如果有人可以看一下,我将不胜感激。

图库代码如下:

$(document).ready(function() {
    $('#thumbs ul li a').hover(
        function() {
            var currentBigImage = $('#bigpic img').attr('src');
            var newBigImage = $(this).attr('rev');
            var currentThumbSrc = $(this).attr('rel');
            switchImage(newBigImage, currentBigImage, currentThumbSrc);
        },
        function() {}
    );

    function switchImage(imageHref, currentBigImage, currentThumbSrc) { 
        var theBigImage = $('#bigpic img');

        if (imageHref != currentBigImage) {     
            theBigImage.fadeOut(250, function() {
                theBigImage.attr('src', imageHref).fadeIn(250);

                var newImageDesc = $("#thumbs ul li a img[src='"+currentThumbSrc+"']").attr('alt');
                $('p#desc').empty().html(newImageDesc);
            });         
        }       
    }
});

最佳答案

(function ($) {

    $.fn.gallerify = function (options) {

        var settings = {
            'galleryOption1': 'value',
            'galleryOption2': 'value'
        };

        return this.each(function () {
            // If options exist, lets merge them
            // with our default settings
            if (options) {
                $.extend(settings, options);
            }

            // Do the stuff your gallery does. without
            // mentioning specific selectors like #bla or .bla
            // Only refer to elements relative to $(this)

        });

    };
})(jQuery);


$(function () {
    $('#thumbs').gallerify({
        galleryOption1 : 'makemygallerythebest',
        galleryOption2 : 'buymeabeer'
    });
});

关于jquery - 在同一页面上使用 jquery gallery 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6189008/

相关文章:

javascript - 触摸移动时触发的 css 转换不一致

html - 输入类型不居中

javascript - 在 ChartJS 中添加背景文本

JQuery 将列表项移动到无序列表的末尾

javascript - 如何在 Javascript/jQuery 中模仿 HTML 元素并向其添加属性

带有隐藏行的 jQuery 表斑马条纹

php - 在相同的 css 类中显示相同页面的错误消息

javascript - 在数据表中重绘表时调用 fnRowCallback

javascript - 在命名处理函数中使用 $(this) 和事件

jquery - 如何在 highcharts 中显示具有相同类别和相同 x 轴的不同 y 轴的柱形图和面积图