2014-01-09 160 views
1

我有这段代码,当单击一个URL时,视图将平滑地滚动到该特定的div(同一页)。 但是,我遇到了一些马车。
所以说,我点击了URL,它现在顺利滚动到页面的底部。但是,当我试图用我的鼠标滚轮来停止平滑滚动,但它不起作用。相反,它给了我那种有点怪异的外观。用鼠标滚轮停止平滑滚动

下面的代码 请指点

 <script> 
     $('a').click(function(e){ 

      $('html, body').stop().animate({ 
       scrollTop: $($(this).attr('href')).offset().top 
      }, 1500); 

      return false; 
     }); 
     </script> 

回答

1

事件处理程序添加到windowwheelmousewheel事件,并在他们的处理器调用$("html, body").stop()

+0

请指点一些代码,请...漂亮的新与活动:( –

+0

我想通了,它的工作现在耶感谢 –

0

也许问题是,你不使用文件准备就绪功能。

试试这个:

<script> 
    $(document).ready(function() { // <-- this 
    $('a').click(function(e){ 

     $('html, body').stop().animate({ 
      scrollTop: $($(this).attr('href')).offset().top 
     }, 1500); 

     return false; 
    }); 
    }); 
</script> 
+0

谢谢!回复...但不,我只是试了一下..它仍然不起作用:( –

1

试试这个

<script> 
    $('html, body').bind('mousewheel', function(e){ 
     $(this).stop(); 
    }); 

    $('a').click(function(e){ 
      $('html, body').stop().animate({ 
       scrollTop: $($(this).attr('href')).offset().top 
      }, 1500); 

     return false; 
    }); 
</script> 
+0

它不工作...但我已经想通了。谢谢 –

+0

@madushak我不知道答案适用于这个问题,但它适用于我使用的一个bug d面对。 – Muhammed