SoFunction
Updated on 2025-04-03

Mouse wheel programming


function handle(delta) {
 if (delta < 0)
 …;
 else
 …;
}

/** Event handle
 */
function wheel(event){
 var delta = 0;
 if (!event) /* For IE. */
 event = ;
if () { /* IE or Opera. */
 delta = /120;
/** In Opera9, event handling is different from IE
 */
 if ()
 delta = -delta;
} else if () { /** Compatible with Mozilla. */
 /** In Mozilla, sign of delta is different than in IE.
 * Also, delta is multiple of 3.
 */
 delta = -/3;
 }
/** If the increment is not equal to 0, it will be triggered
* The main function is to test the roller roll upward or downward
 */
 if (delta)
 handle(delta);
}

/** Initialization */
if ()
/** Mozilla's DOM-based scroll wheel event **/
 ('DOMMouseScroll', wheel, false);
/** IE/Opera. */
= = wheel;