views:

441

answers:

2

Hello everybody, I'd like my page to go to the top when certain anchor is clicked, I had this done before but I lost the code somewhere, here is how I tried to do it but its not working its scrolling usual super fast.

 $('a[href=#top]').click(function () {
        $('body').animate({
                scrollTop: 0
        },
        50);
});

Can anybody help me, tnx

+1  A: 

$('a[href=#top]').click(function(){

$('html, body').animate({scrollTop:0}, 'slow');

});

Perhaps?

c0mrade
+1  A: 

When you pass 50 as the second parameter to animate, that is 50 milliseconds. See the animate documentation. Either pass a larger number, or as c0mrade suggested, simply pass 'slow' .

wsanville