0

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

        }
    })
});
4

3 回答 3

1

尝试:

$(window).load

代替

$(document).load
于 2012-12-22T22:39:20.333 回答
1

尝试 $(window).load() 而不是 $(document).load()

$(window).load(function () {
  // run code
});
于 2012-12-22T22:40:46.640 回答
0

我认为 $.load 是实际上在给定 url(第一个参数)上执行 AJAX 请求的方法。如果你想对 document.load 事件做一些事情,你必须使用 $(document).ready()

于 2012-12-22T22:44:31.497 回答