【发布时间】:2017-08-14 23:16:09
【问题描述】:
我有一个页面,它在滚动事件中向自身添加和删除一些内容。
现在使用 Chrome 时(IE11 似乎没有这种行为),每当向页面添加和删除内容时,都会生成滚动事件(我猜是为了保持客户端视图在页面更改时保持一致)。
我不想要这个。内容变化产生的滚动事件会触发更多的内容变化,进而触发更多的滚动事件。
关于如何阻止所有浏览器的这种行为的任何建议?我不希望发生任何自动滚动。我只想注册用户滚动。
这是一些简单的示例代码。单击“单击”按钮将重新调整彩色差异并使页面自行滚动(在 Chrome 中,而不是 IE11 中)...
function removeStuff(){
var elem = document.getElementById("center");
document.getElementById("container").removeChild(elem);
document.getElementById("container").appendChild(elem);
}
#top {
background-color: green;
height:1500px;
}
#center {
background-color: blue;
height:1000px;
}
#bottom {
background-color: red;
height:1500px;
}
<div id="container">
<div id="top"></div>
<div id="center"></div>
<button id="button" onclick="removeStuff()">click</button>
<div id="bottom"></div>
</div>
【问题讨论】:
标签: javascript html google-chrome cross-browser