鼠标的滚轮事件 mousewheel

如果要相应 鼠标的滚轮事件,先要连接一下 jQ的一个鼠标滚轮插件
jquery.mousewheel.js 下载地址:

 http://plugins.jquery.com/files/jquery.mousewheel.3.0.2.zip 
然后使用的时候 有个代码范例:

 jQuery(function($) {

    $('div.mousewheel_example')
        .bind(
'mousewheel'function(event, delta) { //两个参数
            
var dir = delta > 0 ? 'Up' : 'Down', //向上还是向下
                vel 
= Math.abs(delta); //delta 可能的值是 1 和 -1
            $(
this).text(dir + ' at a velocity of ' + vel);
            
return false;
        });
});

今天利用这个功能扩展了一下原来写的相应键盘的切换效果,现在让它也相应鼠标滚轮:

$("#area").mousewheel(function(event, delta) {
            
if (delta > 0){
                keydown();
                }
else if (delta < 0){
                    keyup();
                    }
            
            
return false// prevent default

        }); 

 DEMO地址:

 http://nba.titan24.com/focus/kikx/ABCnews_06-09.html

原文地址:https://www.cnblogs.com/trance/p/1499713.html