javascript控制鼠标中键滑动

MouseWheel.js的代码如下:

var MouseWheel_Count=0;

function MouseWheel$handle(delta){

	MouseWheel_Count++;

	if(MouseWheel_Count>1)	return;

    if (delta < 0) //小于0向下滚动,大于0向上滚动

       //        alert("向下滚动");

    else 

       //        alert("向上滚动");

	setTimeout("MouseWheel$CountMinus();",500);

}



function MouseWheel$CountMinus()

{

	MouseWheel_Count=0;

}



/** 事件句柄

 */

function MouseWheel$wheel(event){

    var delta = 0;

    if (!event) /* For IE. */ 

        event = window.event;

    if (event.wheelDelta) { /* IE或者Opera. */

        	delta = event.wheelDelta/120;

//        delta = event.wheelDelta;

        /** 在Opera9中,事件处理不同于IE

         */

        if (window.opera) 

            delta = -delta;

    }

    else 

        if (event.detail) { /** 兼容Mozilla. */

            /** In Mozilla, sign of delta is different than in IE.

         * Also, delta is multiple of 3.

         */

            delta = -event.detail / 3;

        }

    /** 如果 增量不等于0则触发

     * 主要功能为测试滚轮向上滚或者是向下

     */

    if (delta) 

        MouseWheel$handle(delta);

}

你可能感兴趣的:(JavaScript)