Intersection of events.

I am looking for a good resource to normalize events in an event object. I try to do it myself, but I continue to feel that I'm missing something.

Here is what I still say if I missed something.

var eFix = function(e) { e = e || window.event; e.target = e.target || e.srcElement; e.offsetX = e.offsetX || e.layerX; e.offsetY = e.offsetY || e.layerY; e.relatedTarget = e.relatedTarget || e.type == 'mouseover' ? e.fromElement : e.toElement; e.target = e.target || e.srcElement; if (target.nodeType === 3) target = target.parentNode; //Safari bug return e; }; 

Has anyone seen the full normalization function? Did I miss something? (Needless to say, we are going for the W3C model, not IE)

+6
javascript cross-browser javascript-events events dom-events
source share
1 answer

There is another problem in your code:

e.layerX only works with positioned elements, so at least you need to add a "position: relative" to your element to work. Secondly, e.offsetX only works correctly in IE8 and later, so you should probably refrain from using it anyway (although I am using them right now, but it only needs to work in certain browsers).

+2
source share

All Articles