Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<style>
body {
margin: 0;
width: 1000px;
height: 1000px;
}
div {
width: 50px;
height: 50px;
}
#scroller {
position: absolute;
left: 150px;
top: 150px;
width: 200px;
height: 200px;
overflow: scroll;
outline: 1px solid black;
}
#scroller-content {
position: relative;
width: 400px;
height: 400px;
}
#anchor1 {
position: absolute;
left: 75px;
top: 100px;
background: orange;
}
#anchor2 {
position: absolute;
left: 175px;
top: 100px;
background: teal;
}
#f1 {
position: fixed;
left: 150px;
top: 150px;
background: yellow;
}
#f2 {
position: fixed;
left: 250px;
top: 150px;
background: aqua;
}
</style>
<div id="scroller">
<div id="scroller-content">
<div id="anchor1"></div>
<div id="anchor2"></div>
</div>
</div>
<div id="f1"></div>
<div id="f2"></div>
<script>
document.documentElement.scrollLeft = 100;
document.documentElement.scrollTop = 100;
let scroller = document.getElementById('scroller');
scroller.scrollLeft = 25;
scroller.scrollTop = 50;
</script>