2016-02-24 213 views
1

上滚动动画这是我的查询代码:jQuery代码不工作的

$(document).ready(function() { 

     $('.js--scroll-to-discount').click(function() { 
      $('html, body').animate({scrollTop: $('js--section-discount-opt').offset().top}, 1000); 
     }); 

}); 

这是按钮的HTML代码被点击:

<a class="btn btn-full js--scroll-to-discount" href="#">I'm ready Dallas</a> 

这是部分动画应该把你的页面中:

<section class="discount-city js--section-discount-opt"> 

回答

1

你在你的代码有错误

$(document).ready(function() { 

     $('.js--scroll-to-discount').click(function() { 
      $('html, body').animate({scrollTop: $('js--section-discount-opt').offset().top}, 1000); 
     }); 

}); 

应该

$(document).ready(function() { 

     $('.js--scroll-to-discount').click(function() { 
      $('html, body').animate({scrollTop: $('.js--section-discount-opt').offset().top}, 1000); 
     }); 

});