滑鼠滾輪事件小析

2022-08-16 21:54:18 字數 605 閱讀 7226

一、事件

ie/chrome: onmousewheel(火狐中無此事件)

firefox: dommousescroll (必須用addeventlistener繫結事件)

相容性問題解決:

if(odiv.addeventlistener)

odiv.onmousewheel=fn;

二、屬性(代表滾動的方向)

ie/chrome: event.wheeldelta(上滾:120,下滾:-120)

firefox: event.detail(上滾:-3,下滾:3)

相容性問題解決:

var b=true;

if(ev.wheeldelta)

else

if(b>0)else

注:滾動事件也會觸發整個頁面的滾動的預設事件,因此要組織

return false阻止的是標準瀏覽器下obj.on事件名=fn觸發的預設行為,而addeventlistener繫結的事件需通過event下

的preventdefault()方法進行阻止。

相容性問題解決:

if(ev.preventdefault)

return false;

滑鼠滾輪事件

新增事件 有相容性 註冊事件 if document.addeventlistener window.onmousewheel document.onmousewheel scrollfunc ie opera chrome detail與wheeldelta 判斷滾輪向上或向下在瀏覽器中也有相容性...

滑鼠滾輪事件

新增事件 有相容性 註冊事件 if document.addeventlistener window.onmousewheel document.onmousewheel scrollfunc ie opera chrome detail與wheeldelta 判斷滾輪向上或向下在瀏覽器中也有相容性...

滑鼠滾輪事件

滑鼠滾輪事件和鍵盤事件以及滑鼠左右鍵沒本質的區別。2 if document.addeventlistener window.onmousewheel document.onmousewheel scroll ie opera chrome safari 像上面這樣就可以給整個文件繫結滾輪事件。fu...