jQuery 鼠標滾輪插件 jquery.mousewheel.js


jQuery Mousewheel Plugin,用於添加跨瀏覽器的鼠標滾輪支持。
mousewheel事件的處理函數有一點小小的變化,它除了第一個參數event 外,還接收到第二個參數delta。
通過參數delta可以獲取鼠標滾輪的方向和速度。
如果delta的值是負的即-1,那么滾輪就是向下滾動,正的1就是向上。

官方網址:

https://github.com/brandonaaron/jquery-mousewheel

插件方法:

1.為了監聽滾輪事件,該插件引入了mousewheel事件,所以我們可以監聽元素的mousewheel事件

2.該插件還提供了元素快捷方法mousewheel和unmousewheel用於監聽和去掉元素對鼠標滾輪事件支持

例如:

Js代碼   收藏代碼
  1. // using bind  
  2. $('#my_elem').bind('mousewheel', function(event, delta, deltaX, deltaY) {  
  3.     if (window.console && console.log) {  
  4.          console.log(delta, deltaX, deltaY);  
  5.     }  
  6. });  
  7.   
  8. // using the event helper  
  9. $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) {  
  10.     if (window.console && console.log) {  
  11.          console.log(delta, deltaX, deltaY);  
  12.     }  
  13. });  

 

 效果圖:



 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM