Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 滚动时会出现抖动_Javascript_Jquery_Internet Explorer - Fatal编程技术网

Javascript 滚动时会出现抖动

Javascript 滚动时会出现抖动,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,这在除IE之外的所有浏览器中都能很好地工作。 我该如何解决这个问题?当我在IE中滚动时,它非常不稳定 试试这个(): 和CSS: #scroller { position: relative; top: 100px; width: 500px; background: #CCC; height: 100px; margin: 0 auto; } #scroller.top { position: fixed; top: 0;

这在除IE之外的所有浏览器中都能很好地工作。 我该如何解决这个问题?当我在IE中滚动时,它非常不稳定

试试这个():

和CSS:

#scroller {
    position: relative;
    top: 100px;
    width: 500px;
    background: #CCC;
    height: 100px;
    margin: 0 auto;
}

#scroller.top {
    position: fixed;
    top: 0;
    left: 50%;
    margin-left: -250px;
}
编辑:我将设置
宽度
边距
添加到
#滚动条
,设置
左侧:50%
左侧边距:-250px(设置宽度的一半)到.top类

您也可以尝试这个()


你测试的是什么版本的IE?在IE10中对我来说是不稳定的。在IE8中我似乎无法打开这些小提琴。。。小提琴页面的格式都弄乱了。有人知道为什么吗?(我认为小提琴有一些JS错误),我认为JSFIDLE在IE8中不起作用。本质上是和我的一样,但是我的CSS在CSS看起来很棒,如果它的固定边距,更多的思考:O汽车不会把DIV放在屏幕中间。你有解决的办法吗?谢谢。我更新了答案和小提琴,以反映屏幕中央的固定宽度div。您可以使用基于%的宽度执行相同的操作。
$(window).scroll(function () {
    if ($(window).scrollTop() > 100) {
        $('#scroller').addClass("top");
    }
    else {
        $('#scroller').removeClass("top");
    }
});
#scroller {
    position: relative;
    top: 100px;
    width: 500px;
    background: #CCC;
    height: 100px;
    margin: 0 auto;
}

#scroller.top {
    position: fixed;
    top: 0;
    left: 50%;
    margin-left: -250px;
}
$(window).scroll(function () {
    if ($(window).scrollTop() > 100) {
        //$('#scroller').css('top', $(window).scrollTop());
        $('#scroller').css('top', '0px');
        $('#scroller').css('position', 'fixed');
    }
    else
    {
        $('#scroller').css('top', '100px');
        $('#scroller').css('position', 'absolute');
    }
}
);