Monday, September 18, 2006

portable and rewrote onmousewheel function

I did a simple version of onmousewheel, then I add JSL and $DOM objects dependencies, then I've came back to single portable version without dependencies that's simpler than first one :D

onmousewheel isn't a window or document event, onmousewheel is a generic Element event. While a generic event as onclick, onmouseover, onmouseout is called only above the element, onmousewheel will be called only above the element too, that's all!

No more double events (onmouseover that activates onmousewheel and onmouseout that deactivates onmousewheel) ... just the event.

* function onmousewheel,
* onmousewheel(element:Object [, callback:Function]):Void
* @param Object window, document or DOM.element to use with callback
* @param Function callback function with element scope (.call(...)) and delta wheel value as single parameter
* @return Void
function onmousewheel(element, callback) {

// @author Andrea Giammarchi []
// @license MIT []
// @credits Adomas Paltanavicius []

function __onwheel(event) {
var delta = 0;
if(event.wheelDelta) {
delta = event.wheelDelta / 120;
delta = -delta;
else if(event.detail)
delta = -event.detail / 3;
if(delta), delta);
event.returnValue = false;
return false;

if(element.addEventListener && !window.opera)
element.addEventListener("DOMMouseScroll", __onwheel, false);
element.onmousewheel = (function(base){return function(evt){
if(!evt) evt = window.event;
if(base), evt);
return __onwheel(evt);

And here you can view the always updated version or the example page.

No comments:

Post a Comment