<!DOCTYPE html> | |
<style> | |
body { | |
height: 2000px; | |
margin: 0; | |
overflow: hidden; | |
padding: 0; | |
} | |
.sticky { | |
width: 200px; | |
height: 200px; | |
background-color: green; | |
display: inline-block; | |
position: relative; | |
top: 200px; | |
} | |
.block { | |
width: 200px; | |
height: 200px; | |
background-color: red; | |
} | |
</style> | |
<script> | |
function doTest() | |
{ | |
window.scrollTo(0, 200); | |
} | |
window.addEventListener('load', doTest, false); | |
</script> | |
<span class="sticky"></span> | |
<div class="block"></div> | |