Can anyone recommend a βbetterβ approach for tying a scrollbar to the top of an element when scrolling a page?
For example, if my layout was as follows:
<div id="section-one" style="width: 100%; height: 600px;"> Section One </div> <div id="section-two" style="width: 100%; height: 600px;"> Section Two </div> <div id="section-three" style="width: 100%; height: 600px;"> Section Three </div> <div id="section-four" style="width: 100%; height: 600px;"> Section Four </div>
If a user browsed the first section and started browsing down, and the second section began to take part in the browser viewing window, I would like the browser to automatically snap to the top of the next div.
I am familiar with .scroll () and .scrollTop, but a little unsure where to go from here.
source share