<!DOCTYPE html> | |
<style> | |
body { | |
margin: 0; | |
height: 2000px; | |
overflow: hidden; /* hide scrollbars */ | |
} | |
#container { | |
background-color: green; | |
width: 200px; | |
height: 400px; | |
outline: 2px solid black; | |
overflow: auto; | |
} | |
.box { | |
width: 200px; | |
height: 200px; | |
} | |
.sticky { | |
position: relative; | |
top: 0px; | |
background-color: red; | |
} | |
</style> | |
<script> | |
function doTest() | |
{ | |
window.scrollTo(0, 200); | |
} | |
window.addEventListener('load', doTest, false); | |
</script> | |
<div id="container"> | |
<div class="sticky box"></div> | |
</div> |