javascript 兼容鼠標滾輪事件
更新時間:2009年04月07日 21:40:14 作者:
瀏覽地圖時,使用鼠標滾輪來放大和縮小。即用到了滾輪事件。
這個事件在標準下和IE下是有區(qū)別的。firefox是按標準實現(xiàn)的,事件名為"DOMMouseScroll ",IE下采用的則是"mousewheel "。
當然一行代碼就解決了兼容問題
var mousewheel = document.all?"mousewheel":"DOMMouseScroll";
事件屬性,IE是event.wheelDelta,F(xiàn)irefox是event.detail 屬性的方向值也不一樣,IE向上滾 > 0,F(xiàn)irefox向下滾 > 0。
最新的jquery1.3.2仍然沒有增加滾輪事件,但可以用jquery的bind去綁定任何事件,當然得加上上面那句。
不過jquery有個插件已經加上了該功能。見http://brandonaaron.net/code/mousewheel/demos
這樣使用:
$('div.mousewheel_example').mousewheel(fn);
$('div.mousewheel_example').bind('mousewheel', fn);
當然一行代碼就解決了兼容問題
復制代碼 代碼如下:
var mousewheel = document.all?"mousewheel":"DOMMouseScroll";
事件屬性,IE是event.wheelDelta,F(xiàn)irefox是event.detail 屬性的方向值也不一樣,IE向上滾 > 0,F(xiàn)irefox向下滾 > 0。
最新的jquery1.3.2仍然沒有增加滾輪事件,但可以用jquery的bind去綁定任何事件,當然得加上上面那句。
不過jquery有個插件已經加上了該功能。見http://brandonaaron.net/code/mousewheel/demos
這樣使用:
復制代碼 代碼如下:
$('div.mousewheel_example').mousewheel(fn);
$('div.mousewheel_example').bind('mousewheel', fn);
相關文章
js操作Xml(向服務器發(fā)送Xml,處理服務器返回的Xml)(IE下有效)
js操作Xml(向服務器發(fā)送Xml,處理服務器返回的Xml)(暫只IE下有效)2009-01-01javascript制作的網頁側邊彈出框思路及實現(xiàn)代碼
這篇文章主要介紹了javascript制作的網頁側邊彈出框思路及實現(xiàn)代碼,需要的朋友可以參考下2014-05-05