HTML5画布鼠标滚轮事件

8

我似乎无法在Firefox中的HTML5画布中获取onMouseWheel事件。下面的代码片段在Chrome和IE9中按预期工作,但在Firefox中只接收点击事件:

<!DOCTYPE html>
<html>
<body>
<canvas id="TestCanvas" tabindex="2" onmousewheel="window.alert('wheel!')" onclick="window.alert('click!')" style="width:90%;height:90%;margin-left:auto;margin-right:auto border:1px solid green;"></canvas>
</body>
</html>

根据我看到的规范,onMouseWheel 应该是 HTML5 元素上的标准事件。我做错了什么吗?
1个回答

11

Firefox不支持mousewheel事件,详见这里。(我刚在Firefox4上测试了一下,看起来它仍然不支持。)

相反,你可以使用DOMMouseScroll事件,但无法通过DOM属性进行附加,必须使用addEventListener替代。

这里是一个使用jQuery的jsFiddle示例


谢谢Nathan,这在FF 4中有效。这是仅限于Firefox的事件吗? - Ryan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接