控制鼠标中键的演示代码

发布时间:2015-2-19 18:29:7 作者:小五 点击:

<html>
<head>
<script type="text/javascript">
function handle(delta) {
var s = delta + ": ";
if (delta <0)
s += "down";
else
s += "up";
document.getElementById('delta').innerHTML = s;
}//from comingcoin.com
function wheel(event){
var delta = 0;
if (!event) event = window.event;
if (event.wheelDelta) {
delta = event.wheelDelta/120;
if (window.opera) delta = -delta;
} else if (event.detail) {
delta = -event.detail/3;
}
if (delta)
handle(delta);
}
/* Initialization code. */
if (window.addEventListener)
window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
</script>
</head>
<body>
<div id="delta">滚动鼠标中间的滚轮可以看到效果</div>
</body>
</html>

留言列表

发表留言:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。