我有一个页面,在滚动事件中添加和删除一些内容.
现在,当使用Chrome(IE11似乎没有这种行为)时,无论何时添加内容并将其删除到页面,都会生成滚动事件(我猜是为了保持客户端视图在页面更改上保持一致).
我不想要这个.在内容更改上生成的滚动事件将触发更多内容更改,这将更多地触发更多滚动事件.
有关如何为所有浏览器停止此行为的任何建议?我不希望任何自动滚动发生.我只想要注册用户滚动.
这是一些简单的示例代码.单击"单击"按钮将重新调整彩色差异并使页面自动滚动(在Chrome中,而不是IE11)...
function removeStuff(){
var elem = document.getElementById("center");
document.getElementById("container").removeChild(elem);
document.getElementById("container").appendChild(elem);
}
Run Code Online (Sandbox Code Playgroud)
#top {
background-color: green;
height:1500px;
}
#center {
background-color: blue;
height:1000px;
}
#bottom {
background-color: red;
height:1500px;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
<div id="top"></div>
<div id="center"></div>
<button id="button" onclick="removeStuff()">click</button>
<div id="bottom"></div>
</div>
Run Code Online (Sandbox Code Playgroud)