I am trying to scroll to a targeted element on my page after I've scrolled down a certain distance from the top of the page. So the scroll to the element is triggered by a .scroll() event. I have been able to do this using the following code:
$( document ).scroll( function( e ) {
if ( $(document).scrollTop() > 250 ) {
$('html, body').animate({
scrollTop: $("#cy-hero-image").offset().top
}, 650);
}
});
However the problem is that once this event has been triggered by the scroll the page sticks to this scroll position. How can I write this code that it only jumps to this page position once when scrolled from the top of the page?
Here is the JSFiddle of what I have so far.