Firefox scrollTop重置zIndex更改

时间:2011-02-05 00:36:06

标签: javascript firefox scrolltop

每当我更改给定div的zIndex(甚至是相同的值)时,其scrollTop属性将重置并向后滚动以启动。这会对我的网站造成非常难看的效果(重新绘制时整个div上的减速和黑色矩形)。在scrollTop重置之后,我可以将其设置回来,但这会导致另一个丑陋的重绘。

这个FF错误让我发疯!我在mozilla https://bugzilla.mozilla.org/show_bug.cgi?id=623937中提交了一个错误,但他们并不关心它!请问,如果有人知道如何使用一些javascript魔法来解决这个问题?也许玩HTMLElement原型以某种方式覆盖scrollTop?

这里有一个小测试案例“

<html>
<head>
<style type="text/css">
div#parentDiv
{
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 200px;
background-color: green;
}
div#elementToScroll
{
position: absolute;
top: 40px;
left: 40px;
width: 200px;
height: 100px;
overflow-y: hidden;
background-color: blue;
color: white;
}
</style>
</head>

<body>

<div id="parentDiv">
This is the parent DIV
<div id="elementToScroll">This is the child div with overflow-y: hidden and content a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of ; </div>
</div>

<script>
var parentDIV = document.getElementById("parentDiv");
var elementToScroll = document.getElementById("elementToScroll");
alert ("elementToScroll.scrollTop initial: " + elementToScroll.scrollTop);
elementToScroll.scrollTop = 20;
alert ("We set elementToScroll.scrollTop = 20: current value is: " + elementToScroll.scrollTop);
parentDIV.style.zIndex = 0;
alert ("We set parentDIV.style.zIndex and now elementToScroll.scrollTop is: " + elementToScroll.scrollTop);
</script>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

我测试过,Firefox 4没有任何问题:

enter image description here