Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  63] [ 7]  / answers: 1 / hits: 43719  / 13 Years ago, thu, may 5, 2011, 12:00:00

Just wondering if its possible to scroll to a certain div's position on a page onclick. I can't seem to find anywhere on the internet where this is documented.



My idea is to click a button, and it will take you to the position of that div on the page, possible by the div ID.



Regards,



Taylor


More From » jquery

 Answers
41

Im not sure when you want the event to fire so here is the generic version



$(selector).click(function() {
//scroll to div
});


If you want a <button/> with an id of myButton that when clicked will cause you to scroll to a <div/> with and id of myDiv over the course of half a second:



$('#myButton').click(function() {
//optionally remove the 500 (which is time in milliseconds) of the
//scrolling animation to remove the animation and make it instant
$.scrollTo($('#myDiv'), 500);
});


Using the jQuery ScrollTo plugin.


[#92381] Wednesday, May 4, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mahogany

Total Points: 645
Total Questions: 107
Total Answers: 98

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
mahogany questions
;