Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  38] [ 4]  / answers: 1 / hits: 73553  / 12 Years ago, mon, october 22, 2012, 12:00:00

I'm using this link:



<a class= onclick=location.href='#top' href=superContent>superContent</a>


It does two things at once:




  1. Jumps user to top of the page

  2. Performs this other (unrelated) ajax load function



Everything works great, except I'm trying to figure out how to get it to scroll to the top more smoothly. I've tried adding .scroll to attach it to my jquery scrollTo plugin, but nothing happens, which probably has something to do with the fact that I'm using javascript onclick, while the href attribute does something else entirely.



Is there a way to attach animated smooth-scrolling to onclick=location.href='#top' ?


More From » scrolltop

 Answers
4

Try this, it animates the scrollTop() function.



Set link's id:



<a id=link>link</a>


jquery to scroll:



$('#link').click(function(e){
var $target = $('html,body');
$target.animate({scrollTop: $target.height()}, 500);
});

[#82416] Sunday, October 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;