Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Scroll down page a set increment (in pixels) on click?

Tags:

jquery

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.

like image 981
bcWeb Avatar asked Apr 17 '10 17:04

bcWeb


People also ask

What is a scroll event in JavaScript?

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.

How do I trigger a scroll event manually?

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.

How do I detach a scroll bar?

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" ) .

What is the purpose of the scroll () method?

The scroll() method triggers the scroll event, or attaches a function to run when a scroll event occurs.


1 Answers

var y = $(window).scrollTop();  //your current y position on the page $(window).scrollTop(y+150); 
like image 125
Mohamed Hafez Avatar answered Nov 06 '22 17:11

Mohamed Hafez