I want to write a jquery function that will take a number of div elements by id or class and the screen scroll so that they are in view. I know that this may not be possible if the divs are spread over the page and not possible to get all in view, but would like to be able to get some in view for the user to be aware off.
Any tips on how I can do this?
If you have a selector you can just use
.scrollTop()to go to the first element the selector matches, like this:Or to animate it so it’s not an immediate jump there, use
.animate():