Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS忽略条件中的setTimeOut_Javascript_Jquery_Html - Fatal编程技术网

Javascript JS忽略条件中的setTimeOut

Javascript JS忽略条件中的setTimeOut,javascript,jquery,html,Javascript,Jquery,Html,我在脚本标记中有此代码: var ya = true setInterval(function() { if($(document).scrollTop() >= 135){ $('header').css({ "height": 50, "position":"fixed", "width":"100%", "top":0, "z-index":

我在
脚本
标记中有此代码:

var ya = true
setInterval(function() {
    if($(document).scrollTop() >= 135){
        $('header').css({
            "height": 50,
            "position":"fixed",
            "width":"100%",
            "top":0,
            "z-index":10000
        });
        $('header nav').css({
            "margin-top":0
        });
        $('#social').css({
            "margin-top":0
        });
        $("body").css({
            "margin-top":135
        });
        $("#luis").css({
            "display":"none"
        });
        $('header').addClass('animated fadeInDown');
        ya = false;
    }else if(!ya){

        $('header').addClass('animated fadeOutUp');
        setTimeout(function(){
            $('header').addClass('fadeInDown');
            $('header').css({
                "height": 135,
                "position":"static",
                "width":"100%",
                "top":0,
                "z-index":10000
            });
            $('header nav').css({
                "margin-top":44
            });
            $('#social').css({
                "margin-top":43
            });
            $("body").css({
                "margin-top":0
            });

            $("#luis").css({
                "display":"inline-block"
            });
            ya = true
        }, 400);


    }
}, 100);
对。我有jQuery,当代码到达
if
时,样式将应用


问题是
setTimeOut
中的代码不起作用,但条件工作正常,因为
setTimeOut
之外的代码按预期工作。。。即使我将
setInterval
中的时间更改为10000(因为我认为问题在于它无法完成该过程),它仍然无法工作。

JavaScript不会“忽略它”。因此,这两件事中的一件发生了:1)if条件分支从未执行,或2)它确实运行,但结果/副作用被误解或丢失。从那开始。既然你声称#1不是问题所在,那就把注意力集中在#2上。用分号把这两个
ya=true
合起来怎么样?@香蕉没什么区别。JavaScript有ASI。实际上,ya得到“true”,因为
中的代码如果
正常工作…我打赌你的代码工作正常,你只是在
/*…这里的操作也正常工作…*/
/*但是它没有*/
并且没有达到setTimeout函数。请发布您的完整代码,以便我们可以看到您在那里做了什么