Javascript 滚动时会出现抖动
这在除IE之外的所有浏览器中都能很好地工作。 我该如何解决这个问题?当我在IE中滚动时,它非常不稳定 试试这个(): 和CSS: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;
#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');
}
}
);