Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  147] [ 4]  / answers: 1 / hits: 44160  / 13 Years ago, sat, november 12, 2011, 12:00:00

I'm trying to figure out how to, upon pageload, automatically scroll to the bottom of a page (which has been described sufficiently here) and then scroll back up automatically upon reaching the bottom of the page. I can find the automatic scrolling to the bottom, but I can't figure out how to identify when I'm at the bottom of the page, and how to scroll back up when I am. I'd do this using generic Javascript (or JQuery).



Thanks in advance!


More From » jquery

 Answers
41

Try this:
http://jsfiddle.net/yjYJ4/



$('html, body').animate({ scrollTop: $(document).height() - $(window).height() }, 1000, function() {
$(this).animate({ scrollTop: 0 }, 1000);
});


You can view the demo in full screen here: http://jsfiddle.net/yjYJ4/embedded/result/



Change the number 1000 if you want to increase or decrease speed.



Works fine in Chrome, Firefox and IE 6-9.



EDIT:



If you need it to repeat forever (not recommended...) you could do like this: http://jsfiddle.net/QUCWe/


[#89157] Friday, November 11, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kieraelsies

Total Points: 718
Total Questions: 103
Total Answers: 104

Location: England
Member since Sun, May 21, 2023
1 Year ago
kieraelsies questions
Tue, Aug 3, 21, 00:00, 3 Years ago
Tue, Feb 23, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Mon, Sep 16, 19, 00:00, 5 Years ago
;