Today, I found a function that responds to the scroll wheel on the Internet and changed it to the following class.
Copy codeThe Code is as follows:
Function wheelEvent (obj, handle)
{
This. handle = handle;
// Different events between Firefox and IE
Window. addEventListener? Obj. addEventListener ("DOMMouseScroll", this. wheel, false): (obj. onmousewheel = this. wheel );
}
WheelEvent. prototype. wheel = function (event)
{
Var ev = event | window. event;
Var delta = ev. wheelDelta? (Ev. wheelDelta/120): (-ev. detail/3); // Firefox using 'wheeldelta' IE using 'detail'
Eval ('delta? '+ Parent. handle +' (delta): null ;');
}
When using this function, you need to define an execution function to operate based on the values obtained from the preceding class and add events to the specified webpage element. For example
Copy codeThe Code is as follows:
Function handle (delta)
{
Document. getElementById ('text'). scrollTop-= delta * 20;
}
New wheelEvent (document. getElementById ('text'), 'handle ');
In the preceding example, the first parameter is the webpage element with the id of text, and the second parameter is the name of the execution function handle.
The handle function must have only one parameter, delta. When the scroll wheel goes up, delta is greater than 0, and down is less than 0. In the preceding example, the handle function is used to implement the scroll bar function on the div using the scroll wheel.