当我像这样关注DOM时,如何阻止IE中的scrollTop
更改?
<html>
<head>
<title>demo</title>
<script type="text/javascript">
function test() {
document.getElementById('div1').focus();
//document.body.scrollLeft = 0;
//document.body.scrollTop = 0;
}
</script>
</head>
<body onload="test()" scroll='no' style='overflow:hidden'>
<div id="div0" style="width:1400px;height:700px;background:#333333;position:absolute;"> </div>
<div id="div1" style="top:1500px;width:1500px;height:300px;background:#DDDDDD;position:absolute; "> </div>
</body>
</html>
我不想重置scrollTop=0
,因为它会使身体发抖。
答案 0 :(得分:0)
这是你想要的效果吗?
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<style>
body {
margin: 0;
padding: 0;
}
#div0, #div1 {
position: absolute;
height: 100px;
width: 100%;
}
#div0 {
background: #333;
}
#div1 {
background: #ddd;
}
</style>
</head>
<body>
<div id="div0" style="height:700px;"> </div>
<div id="div1" style="top:1500px;height:300px;"> </div>
<script type="text/javascript">
(function() {
document.getElementById('div1').focus();
})();
</script>
</body>
</html>