javascript - jQuery load() 不起作用

标签 javascript jquery

我的加载事件问题是,当我测试页面时它不起作用(不隐藏预加载器图像),但是当我将函数放入 .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(function () {
  // run code
});

关于javascript - jQuery load() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14007139/

相关文章:

jquery - 当我使用 .ajax 和 JSONP 时,如何处理失败的 JSON 请求?

javascript - 如何使用 Javascript 将所需功能添加到我的个人列表中?

javascript - 过滤动态html表格

javascript - 如何使用从 Redux 返回的嵌套数据结构而不遇到 'cannot access property x of undefined' 等错误?

javascript - Vue.js 在每个页面上重置索引和长度

javascript - 在正则表达式中允许 "/"正斜杠

javascript - 加载ajax模式时如何不重新加载

javascript - GraphQL - 传播输入参数

javascript - 如何在用户身份验证后打开新窗口并提取参数

jquery - 第一次点击时跳转动画,第二次点击时正常