簡體   English   中英

jQuery load()不起作用

[英]jQuery load() doesn't work

我的加載事件的問題是當我測試頁面時它不起作用(不要隱藏預加載器圖像),但是當我把函數放在.ready()中時,函數可以工作(它隱藏)。

這是代碼:

JAVASCRIPT:

$(document).load(function(){
    $("#loaderHolder").hide("fast");
});
$(document).ready(function(){
    $('#slider').cycle();
    $('.sf-menu').superfish({
        autoArrows: false
    });
    $('.scroll').slimScroll({
        height: '590px',
        wheelStep:5,
        size:'15px',
        width:'590px',
        position: 'left',
        railColor:'#c5c5c5',
        color:'#a2a1a1',
        railVisible:true,
        alwaysVisible:true,
        distance: '565px'
    });
    $('.scroll').css('width','550px');
    $('.gallery').colorbox();
    $('#gallery img').hover(function(){ $(this).fadeTo(500, 0.3)}, function(){$(this).stop().fadeTo(500, 1)})
    $("#home-link").click(function(){
        if ($(".active").length == 0)
        {
            return ;
        }
        else
        {
            var active = $(".active");
            active.css("display","inline-block");
            active.hide("slide",{},700);
            active.attr("class","vanished");

        }
    });
    $("#about-link").click(function(){
        if ($(".active").length == 0)
        {
            var hidden = $("#about");

            hidden.show("slide",{},700);
            hidden.attr("class","active");
        }
        else
        {
            if ($("#about").attr("class") == "active")
            {
                return ;
            }
            else
            {
                var active = $(".active");
                active.css("display","inline-block");
                active.hide("slide",{},700);
                active.attr("class","vanished");
                var hidden = $("#about");

                hidden.show("slide",{},700);
                hidden.attr("class","active");
            }

        }
    })
    $("#starters-link").click(function(){
        if ($(".active").length == 0)
        {
            var hidden = $("#starters");

            hidden.show("slide",{},700);
            hidden.attr("class","active");
        }
        else
        {
            if ($("#starters").attr("class") == "active")
            {
                return ;
            }
            else
            {
                var active = $(".active");
                active.css("display","inline-block");
                active.hide("slide",{},700);
                active.attr("class","vanished");
                var hidden = $("#starters");
                hidden.show("slide",{},700);
                hidden.attr("class","active");
            }

        }
    })
    $("#gallery-link").click(function(){
        if ($(".active").length == 0)
        {
            var hidden = $("#gallery");

            hidden.show("slide",{},700);
            hidden.attr("class","active");
        }
        else
        {
            if ($("#gallery").attr("class") == "active")
            {
                return ;
            }
            else
            {
                var active = $(".active");
                active.css("display","inline-block");
                active.hide("slide",{},700);
                active.attr("class","vanished");
                var hidden = $("#gallery");
                hidden.show("slide",{},700);
                hidden.attr("class","active");
            }

        }
    })
    $("#contacts-link").click(function(){
        if ($(".active").length == 0)
        {
            var hidden = $("#contacts");

            hidden.show("slide",{},700);
            hidden.attr("class","active");
        }
        else
        {
            if ($("#contacts").attr("class") == "active")
            {
                return ;
            }
            else
            {
                var active = $(".active");
                active.css("display","inline-block");
                active.hide("slide",{},700);
                active.attr("class","vanished");
                var hidden = $("#contacts");
                hidden.show("slide",{},700);
                hidden.attr("class","active");
            }

        }
    })
});

嘗試:

$(window).load

代替

$(document).load

嘗試$(window).load()而不是$(document).load()

$(window).load(function () {
  // run code
});

我認為$ .load是在給定url(第一個參數)上執行AJAX請求的方法。 如果你想在document.load事件上做一些事情,你必須使用$(document).ready()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM