(窗口).load和(document).ready函数是冲突的

时间:2013-01-16 11:45:02

标签: jquery

我试图让2个jquerys工作而不会发生冲突!

这是我的代码:

(function($){ //This functions first parameter is named $
    $(document).ready(function(){
        // tabbed boxes
        $('#tabs div').hide();
        $('#tabs div:first').show();
        $('#tabs ul li:first').addClass('active');
        $('#tabs ul li a').click(function(){ 
            $('#tabs ul li').removeClass('active');
            $(this).parent().addClass('active'); 
            var currentTab = $(this).attr('href'); 
            $('#tabs div').hide();
            $(currentTab).show();
            return false;
        });
    });

    $(window).load(function(){
        // jQuery Lightbox
        var lightboxPath = "/js/jquery-lightbox/";
        $("a[rel='group1']").lightBox({
            imageLoading:lightboxPath+"img/lightbox-ico-loading.gif",
            imageBtnPrev:lightboxPath+"img/lightbox-btn-prev.gif",
            imageBtnNext:lightboxPath+"img/lightbox-btn-next.gif",
            imageBtnClose:lightboxPath+"img/lightbox-btn-close.gif",
            imageBlank:lightboxPath+"img/lightbox-blank.gif"
        });

        // Photo gallery > Standard
        $(".photosgallery-std").sliderkit({
            mousewheel:true,
            shownavitems:7,
            //navfx:"none",
            panelbtnshover:true,
            auto:true,
            circular:true,
            navscrollatend:true,
            counter:true
        });
    })
})(jQuery); 

请任何人都可以帮助:)

1 个答案:

答案 0 :(得分:0)

我认为你必须把它放在()(jQuery);之外:

$(document).ready(function(){
    // tabbed boxes
    $('#tabs div').hide();
    $('#tabs div:first').show();
    $('#tabs ul li:first').addClass('active');
    $('#tabs ul li a').click(function(){ 
        $('#tabs ul li').removeClass('active');
        $(this).parent().addClass('active'); 
        var currentTab = $(this).attr('href'); 
        $('#tabs div').hide();
        $(currentTab).show();
        return false;
    });
});

(function($){ //This functions first parameter is named $
$(window).load(function(){
    // jQuery Lightbox
    var lightboxPath = "/js/jquery-lightbox/";
    $("a[rel='group1']").lightBox({
        imageLoading:lightboxPath+"img/lightbox-ico-loading.gif",
        imageBtnPrev:lightboxPath+"img/lightbox-btn-prev.gif",
        imageBtnNext:lightboxPath+"img/lightbox-btn-next.gif",
        imageBtnClose:lightboxPath+"img/lightbox-btn-close.gif",
        imageBlank:lightboxPath+"img/lightbox-blank.gif"
    });

    // Photo gallery > Standard
    $(".photosgallery-std").sliderkit({
        mousewheel:true,
        shownavitems:7,
        //navfx:"none",
        panelbtnshover:true,
        auto:true,
        circular:true,
        navscrollatend:true,
        counter:true
    });
});
})(jQuery);