ScrollTop的偏移不适用于chrome

时间:2017-10-22 16:14:08

标签: javascript jquery google-chrome

我在jQuery中使用了一个带有偏移量的scrollTop动画函数。 这在safari和firefox中运行良好,但在chrome中不起作用。 这是我的代码:

$(".navbar-collapse ul li a[href^='#']").on('click', function(e) {

   // prevent default anchor click behavior
   e.preventDefault();

   // store hash
   var hash = this.hash;

   // animate
   $('html, body').animate({
       scrollTop: $(hash).offset().top -50
     }, 700, function(){

       // when done, add hash to url
       // (default click behaviour)
       window.location.hash = hash;
     });

});

任何想法为什么它不起作用?

0 个答案:

没有答案
相关问题