为什么这个执行了两次?

发布于 2024-09-29 00:12:11 字数 2859 浏览 6 评论 0原文

我有这样的代码:

$(document).ready(function() {

    $("div #covert, div #coverb").height($(window).height() / 2 + 1);
    $(window).resize(function() {
        $("div #covert, div #coverb").height($(window).height() / 2 + 1);
        covconcr();
    });

    function covconcr() {
        $('div #covercon').css('left', $(window).width() / 2 - $('#covercon').width() / 2);
    }

    covconcr();

    function hidecover() {
        var goup = $('div #covert').height();
    }

    $("div #covercon").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").delay(100).fadeIn("fast", function() {
        $(this).stop();
    });

    $('title').html('Drink86_browser.detection');

    var logoop;

    jQuery.each(jQuery.browser, function() {
        if ($.browser.msie) {
            $('div #covercon').delay(3000, function() {
                $(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
                $('title').html('Drink86_your.browser.is.internet.explorer');
            });
        }
        else if (!$.browser.msie) {
            function update() {
                //$('#site').load('site.php');
                $('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
                covconcr();
                $('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');

                function hidecov() {
                    $('title').html('Drink86_loading_files');
                    $('#covercon').html($('#loading').html());
                    covconcr();
                    var timer = setInterval(function() {
                        $("#loadingpro").html(Math.round($("#progress").width() / 4) + "%");
                    }, 20);
                    $("#progress").animate({
                        width: 400
                    }, 2000, function() {
                        $('title').html('Drink86_');
                        clearInterval(timer);
                        $('#covercon').delay(700).fadeOut('fast', function() {
                            //    if(logoop!="yes"){
                            $('#logobig').css('left', $(window).width() / 2 - $('#logobig').width() / 2).css('top', $(window).height() / 2 - $('#logobig').height() / 2);
                            $('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
                            logoop = "yes";
                            // }
                        });
                    });
                }
                setTimeout(hidecov, 1000);
            }
            setTimeout(update, 3100);
        }
    });
});

使用 #logobigfadeInfadeOut)的操作执行两次。 为什么? 我之前遇到过类似的问题,但后来它们仅在 Firefox 中执行了两次。 有什么想法为什么吗?

I have code like this:

$(document).ready(function() {

    $("div #covert, div #coverb").height($(window).height() / 2 + 1);
    $(window).resize(function() {
        $("div #covert, div #coverb").height($(window).height() / 2 + 1);
        covconcr();
    });

    function covconcr() {
        $('div #covercon').css('left', $(window).width() / 2 - $('#covercon').width() / 2);
    }

    covconcr();

    function hidecover() {
        var goup = $('div #covert').height();
    }

    $("div #covercon").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").delay(100).fadeIn("fast", function() {
        $(this).stop();
    });

    $('title').html('Drink86_browser.detection');

    var logoop;

    jQuery.each(jQuery.browser, function() {
        if ($.browser.msie) {
            $('div #covercon').delay(3000, function() {
                $(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
                $('title').html('Drink86_your.browser.is.internet.explorer');
            });
        }
        else if (!$.browser.msie) {
            function update() {
                //$('#site').load('site.php');
                $('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
                covconcr();
                $('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');

                function hidecov() {
                    $('title').html('Drink86_loading_files');
                    $('#covercon').html($('#loading').html());
                    covconcr();
                    var timer = setInterval(function() {
                        $("#loadingpro").html(Math.round($("#progress").width() / 4) + "%");
                    }, 20);
                    $("#progress").animate({
                        width: 400
                    }, 2000, function() {
                        $('title').html('Drink86_');
                        clearInterval(timer);
                        $('#covercon').delay(700).fadeOut('fast', function() {
                            //    if(logoop!="yes"){
                            $('#logobig').css('left', $(window).width() / 2 - $('#logobig').width() / 2).css('top', $(window).height() / 2 - $('#logobig').height() / 2);
                            $('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
                            logoop = "yes";
                            // }
                        });
                    });
                }
                setTimeout(hidecov, 1000);
            }
            setTimeout(update, 3100);
        }
    });
});

operation with #logobig (fadeIn and fadeOut) is executed twice.
why?
i had previous issues similiar to those but then they were executed twice just in Firefox.
any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

几度春秋 2024-10-06 00:12:11

你到底在想什么

jQuery.each(jQuery.browser, function() { ...

这真的毫无意义。只需查看jQuery.browser(如果必须的话)。

另外,检查“if”语句中是否是 IE,然后检查“else”部分中是否不是 IE,那么,再次...

您问题的直接答案是 jQuery.browser 中可能有两件事,所以你要做两次这些事情。

What exactly were you thinking with

jQuery.each(jQuery.browser, function() { ...

That really makes no sense. Just look at jQuery.browser (if you must).

Also, checking to see if it's IE in an "if" statement, and then if it's not IE in the "else" part, well, again ...

The direct answer to your question is that jQuery.browser probably has two things in it, so you do that stuff twice.

橙味迷妹 2024-10-06 00:12:11

我认为你的问题是你正在迭代 jQuery 浏览器标志的集合,这对于完成你正在做的事情来说不是必需的。如果您在 Firefox 中查看该页面,则 if/elseif 的第二个子句将在每个循环上执行,因为该值永远不会改变。尝试从每个循环中删除该函数,使其看起来像这样:

if ($.browser.msie) {
    $('div #covercon').delay(3000, function() {
        $(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
        $('title').html('Drink86_your.browser.is.internet.explorer');
    });
} else if (!$.browser.msie) {
    function update() {
        //$('#site').load('site.php');
        $('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
        covconcr();
        $('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');

        function hidecov() {
            $('title').html('Drink86_loading_files');
            $('#covercon').html($('#loading').html());
            covconcr();
            var timer = setInterval(function() {
                $("#loadingpro").html(Math.round($("#progress").width() / 4) + "%");
            }, 20);
            $("#progress").animate({
                width: 400
            }, 2000, function() {
                $('title').html('Drink86_');
                clearInterval(timer);
                $('#covercon').delay(700).fadeOut('fast', function() {
                    //    if(logoop!="yes"){
                    $('#logobig').css('left', $(window).width() / 2 - $('#logobig').width() / 2).css('top', $(window).height() / 2 - $('#logobig').height() / 2);
                    $('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
                    logoop = "yes";
                    // }
                });
            });
        }
        setTimeout(hidecov, 1000);
    }
    setTimeout(update, 3100);
}

I think your problem is that you are iterating through the collection of jQuery's browser flags, which is not necessary to accomplish what you are doing. If you were looking at the page in Firefox, the second clause of your if/elseif would execute on every loop, since the value never changes. Try removing that function from the each loop, so that it just looks like this:

if ($.browser.msie) {
    $('div #covercon').delay(3000, function() {
        $(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
        $('title').html('Drink86_your.browser.is.internet.explorer');
    });
} else if (!$.browser.msie) {
    function update() {
        //$('#site').load('site.php');
        $('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
        covconcr();
        $('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');

        function hidecov() {
            $('title').html('Drink86_loading_files');
            $('#covercon').html($('#loading').html());
            covconcr();
            var timer = setInterval(function() {
                $("#loadingpro").html(Math.round($("#progress").width() / 4) + "%");
            }, 20);
            $("#progress").animate({
                width: 400
            }, 2000, function() {
                $('title').html('Drink86_');
                clearInterval(timer);
                $('#covercon').delay(700).fadeOut('fast', function() {
                    //    if(logoop!="yes"){
                    $('#logobig').css('left', $(window).width() / 2 - $('#logobig').width() / 2).css('top', $(window).height() / 2 - $('#logobig').height() / 2);
                    $('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
                    logoop = "yes";
                    // }
                });
            });
        }
        setTimeout(hidecov, 1000);
    }
    setTimeout(update, 3100);
}
双手揣兜 2024-10-06 00:12:11

jQuery.each(jQuery.browser

不要循环遍历“浏览器”对象中的每一项。我怀疑有不止一项!$.browser.msie

jQuery.each(jQuery.browser

Don't loop through each item in the 'browser' object. I suspect there are more than one that are !$.browser.msie

白馒头 2024-10-06 00:12:11

您在 update() 内部调用 setTimeout(hidecov, 1000),然后在 update 外部调用 setTimeOut(update, 3100),因此 hidecov 将在 1000ms 后调用一次,然后 update 将在 3100ms 后调用,并在其中对 hidecov 执行另一个 setTimeout > 1000 毫秒内。

我不确定所有这些代码试图做什么,所以我无法告诉您如何更改它,但我可以明白为什么 hidecov 被调用两次。

You call setTimeout(hidecov, 1000) inside update(), and then setTimeOut(update, 3100) outside of update, so hidecov will be called once after 1000ms, then update will be called in 3100ms, and in there it will do another setTimeout on hidecov in 1000ms.

I'm not sure what all of this code is trying to do so I can't tell you how to change it, but I can see why hidecov is called twice.

淑女气质 2024-10-06 00:12:11

我不是最擅长 JavaScript,所以我可能完全不同意这一点,但看起来 hidecov 可以在调用 update 时运行,然后在 1 秒过去后再次运行。

在 hidecov 中使用带有断点的 Firebug 应该指向它何时运行。

I'm not the best with Javascript, so I might be totally off on this, but it looks like hidecov could be running when update is called, then again when the 1 second has passed.

Using firebug with a breakpoint inside hidecov should point to when it's getting run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文