2014-01-09 254 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