jQuery动画滚动不起作用

问题描述 投票:0回答:2

我正在尝试使jQuery动画滚动功能正常工作,因此当用户单击按钮时,它会很好地向下滚动。我已经完成了多个教程,但动画无法正常工作。当我单击按钮时,它会跳到相应的区域,但突然出现,并且没有任何动画。这是我的代码:

jQuery的:

<script>
    $(function() {
       $('a[href*=#]:not([href=#])').click(function() {
          if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') &&  location.hostname == this.hostname) {
             var target = $(this.hash);
             target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
             if (target.length) {
                $('html,body').animate({
                   scrollTop: target.offset().top
                }, 1000);
             return false;
             }
           }
       });
   });
</script>  

HTML:

<ul class="list-inline intro-social-buttons">

   <li><a href="#moreinfo" class="btn btn-default btn-lg"><i class="fa fa-rocket fa-fw"></i> <span class="network-name">Learn More</span></a>
   </li>

</ul>

然后稍后:

<div class="content-section-a" id="moreinfo">

jquery-1.10.2.js和jQuery.min.map都已链接并加载而没有问题。我做错了什么?

我正在尝试使jQuery动画滚动功能正常工作,因此当用户单击按钮时,它会很好地向下滚动。我已经完成了多个教程,但动画无法正常工作。当我...

javascript jquery html5 jquery-animate
2个回答
2
投票

这可能是问题:


0
投票

有一个简单的CSS解决方案but it's not available on all browsers。我推荐一个jquery答案,但这是一个简洁的CSS技巧,挽救了我的性命,我倾向于分享:)

© www.soinside.com 2019 - 2024. All rights reserved.