jQuery scrollTop not working in Chrome but working in Firefox

后端 未结 15 1804
再見小時候
再見小時候 2020-11-29 02:54

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 w

15条回答
  •  鱼传尺愫
    2020-11-29 03:58

    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;
    });
    

提交回复
热议问题