I'm trying to make a page scroll down 150px from the current position when an element is clicked. So lets say you're roughly halfway scrolled down a page. You click this link, and it will slide you down an additional 150 pixels.
Is this possible with jQuery?
I've been looking at scrollTop and the scrollTo plugin, but I can't seem to connect the dots.
The scroll event occurs when the user scrolls in the specified element. The scroll event works for all scrollable elements and the window object (browser window). The scroll() method triggers the scroll event, or attaches a function to run when a scroll event occurs.
To trigger the event manually, apply .scroll () without an argument: After this code executes, clicks on Trigger the handler will also append the message. A scroll event is sent whenever the element's scroll position changes, regardless of the cause.
A mouse click or drag on the scroll bar, dragging inside the element, pressing the arrow keys, or using the mouse's scroll wheel could cause this event. As the .scroll () method is just a shorthand for .on ( "scroll", handler ), detaching is possible using .off ( "scroll" ) .
The scroll() method triggers the scroll event, or attaches a function to run when a scroll event occurs.
var y = $(window).scrollTop(); //your current y position on the page $(window).scrollTop(y+150);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With