Moak Moak - 9 days ago 6
Javascript Question

Trigger events when the window is scrolled to certain positions

I would like to call functions when the browser window goes beyond a certain point

(e.g the user scrolled the window down beyond 200px from the top

Is there an event I can bind to and then how would I check how much the offset is from the top of the browser to the top of the page?

Answer

You can use onscroll

function testScroll(ev){
    if(window.pageYOffset>400)alert('User has scrolled at least 400 px!');
}
window.onscroll=testScroll

If you want a jQuery solution you can use scroll.

Comments