javascript兼容鼠標滾輪事件_javascript技巧
來源:懂視網
責編:小采
時間:2020-11-27 20:42:23
javascript兼容鼠標滾輪事件_javascript技巧
javascript兼容鼠標滾輪事件_javascript技巧:這個事件在標準下和IE下是有區別的。firefox是按標準實現的,事件名為DOMMouseScroll ,IE下采用的則是mousewheel 。當然一行代碼就解決了兼容問題 代碼如下:var mousewheel = document.allmousewheel:DOMMouseScro
導讀javascript兼容鼠標滾輪事件_javascript技巧:這個事件在標準下和IE下是有區別的。firefox是按標準實現的,事件名為DOMMouseScroll ,IE下采用的則是mousewheel 。當然一行代碼就解決了兼容問題 代碼如下:var mousewheel = document.allmousewheel:DOMMouseScro

這個事件在標準下和IE下是有區別的。firefox是按標準實現的,事件名為"DOMMouseScroll ",IE下采用的則是"mousewheel "。
當然一行代碼就解決了兼容問題
代碼如下:
var mousewheel = document.all?"mousewheel":"DOMMouseScroll";
事件屬性,IE是event.wheelDelta,Firefox是event.detail 屬性的方向值也不一樣,IE向上滾 > 0,Firefox向下滾 > 0。
最新的jquery1.3.2仍然沒有增加滾輪事件,但可以用jquery的bind去綁定任何事件,當然得加上上面那句。
不過jquery有個插件已經加上了該功能。見http://brandonaaron.net/code/mousewheel/demos
這樣使用:
代碼如下:
$('div.mousewheel_example').mousewheel(fn);
$('div.mousewheel_example').bind('mousewheel', fn);
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
javascript兼容鼠標滾輪事件_javascript技巧
javascript兼容鼠標滾輪事件_javascript技巧:這個事件在標準下和IE下是有區別的。firefox是按標準實現的,事件名為DOMMouseScroll ,IE下采用的則是mousewheel 。當然一行代碼就解決了兼容問題 代碼如下:var mousewheel = document.allmousewheel:DOMMouseScro