便便代码人生

关注技术, 偶尔动动手

[原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码

Posted by bianbian on 2008-03-31 22:09

本文Tags: , , , , ,

滚轮IE和Firefox的代码不一样:
IE是mousewheel事件,Firefox是DOMMouseScroll事件
事件属性,IE是event.wheelDelta,Firefox是event.detail
属性的方向值也不一样,IE向上滚 > 0,Firefox向下滚 > 0

  1. //滚轮放大或缩小,基于Prototype 1.6
  2. var scrollfunc = function(event) {
  3.         var direct = 0;
  4.         if (event.wheelDelta) {
  5.                 direct = event.wheelDelta > 0 ? 1 : -1;
  6.         } else if (event.detail) {
  7.                 direct = event.detail < 0 ? 1 : -1;
  8.         }
  9.         zoom(direct);
  10. };
  11. Event.observe(document, 'mousewheel', scrollfunc);
  12. Event.observe(document, 'DOMMouseScroll', scrollfunc); //firefox
标签: , , , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

7 Responses to “[原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码”

  1. radio musik Says:

    musik online…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  2. love life Says:

    love life…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  3. Microsoft Office 2007 Key Says:

    Microsoft Office 2007 Key…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  4. Microsoft Office 2007 Product Key Says:

    Microsoft Office 2007 Product Key…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  5. Office 2007 Enterprise online Says:

    Office 2007 Enterprise online…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  6. office 2010 serial number Says:

    office 2010 serial number…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

  7. office 2007 professional Says:

    office 2007 professional…

    [...]» [原] 支持IE和Firefox的鼠标滚轮事件JavaScript代码 » » 便便代码人生[...]…

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>