views:

80

answers:

3

I have used a scrollTop function in jquery for navigating to top. But strangely 'The smooth animated scroll' stopped working in safari and chrome(scrolling without smooth animation) after I made some changes. But it is working smoothly in Firefox. What could be wrong? Here is the jquery function i used,

jQuery

$('a#gotop').click(function() {
  $("html").animate({ scrollTop: 0 }, "slow");
  //alert('Animation complete.');
  //return false;
});

HTML

<a id="gotop" href="#">Go Top </a>

CSS

#gotop {        Cursor: pointer;
                position: relative;
                float:right;
                right:20px;
                /*top:0px;*/
    }
A: 

I don't think the scrollTop is a valid property. If you want to animate scrolling, try the scrollTo plugin for jquery

http://plugins.jquery.com/project/ScrollTo

Ben Rowe
scrollTop() is valid jQuery: http://api.jquery.com/scrolltop/
Bayard Randel
@Bayard - LOL! it is a *method* and **not** a *css property*...
Reigel
When did I say scrollTop() is a property? You don't need to use a plugin as this function is already implemented in jQuery.
Bayard Randel
@Bayan - your deleted answer would have answer `When did I say scrollTop() is a property?` and besides, the OP want a smooth animation, can `scrollTop()` do smooth?... and it's worth noting that Ben's answer above clearly state, `I don't think the scrollTop is a valid property` and you commented as `scrollTop() is valid jQuery`...
Reigel
thanks @Ben Rowe but i don't want to use additional plugins.
Maju
@Maju fair enough. Glad to see you got your problem sorted however :)
Ben Rowe
+1  A: 

maybe you mean top: 0

$('a#gotop').click(function() {
  $("html").animate({ top: 0 }, "slow", function() { 
                                           alert('Animation complete.'); });
  //return false;
});

from animate docs

.animate( properties, [ duration ], [ easing ], [ callback ] )
properties A map of CSS properties that the animation will move toward.
...

or $(window).scrollTop() ?

$('a#gotop').click(function() {
  $("html").animate({ top: $(window).scrollTop() }, "slow", function() { 
                                                              alert('Animation complete.'); });
  //return false;
});
Reigel
still the animation is not working. Found simple solution.I had to use "body,html" or "html,body" instead of just "html".
Maju
+1  A: 

Try using $("html,body").animate({ scrollTop: 0 }, "slow");

This works for me in chrome.

Aaron Harun
Yes.Thanks.Simple and timesaving.
Maju