Javascript 修复了Firefox和IE中滚动条上的元素跳跃
我有一个元素固定在窗口的右下角。在chrome中,它运行良好,在firefox和IE中,有一种跳跃的效果。 以下是我正在尝试的代码:Javascript 修复了Firefox和IE中滚动条上的元素跳跃,javascript,Javascript,我有一个元素固定在窗口的右下角。在chrome中,它运行良好,在firefox和IE中,有一种跳跃的效果。 以下是我正在尝试的代码: <div style="height: 300px;"></div> <div class="test" style="position: absolute; width: 100%; height: 77px; background-color: #333;"></div> <div style="heigh
<div style="height: 300px;"></div>
<div class="test" style="position: absolute; width: 100%; height: 77px; background-color: #333;"></div>
<div style="height: 1300px;"></div>
$(window).scroll(function () {
var bHeight = $(window).height();
var offset = $(window).scrollTop();
$('.test').css({
top: bHeight + offset - 77 + 'px';
});
});
$(窗口)。滚动(函数(){
var bHeight=$(窗口).height();
var offset=$(window.scrollTop();
$('.test').css({
顶部:bHeight+偏移量-77+像素;
});
});
Ex-Fiddle:在chrome中工作正常,但IE和firefox在scroll上有弹性效果。由于我什么都找不到,谁能提出解决方案?
提前谢谢你的帮助
谢谢,阿基拉,希望我能正确理解你的问题。 是否要修复底部的元素 你可以使用css
.test
{
position: fixed;
bottom: 0;
}
它应该贴在窗口的底部,即使是在页面滚动上。所以我不能给出bottom=0,它应该考虑滚动偏移量,如代码所示。请确保您已删除样式属性中的position:absolute和JS part=>谢谢您的回复。在我的例子中,这个固定的元素被放置在一个绝对位置的内部,并且给定bottom=0使它粘在页面的底部(而不是窗口)