Bind event handler for all browsers by adding prefix automaticlly.
npm install bind-event --save
import bindEvent from 'bind-event';
// bind some event
bindEvent(
document.getElementById('some-element'),
'transitionend',
function(evt) {
if (evt.propertyName == 'opacity' && !evt.target.style.opacity)
evt.target.parentNode.removeChild(evt.target)
}
)
If client's browser support transitionend
event type, it will bind listener function directly to the element. If not, it will automaticlly bind listener function to event type prefix with vendor prefix, such as webkitTransitionend
, mozTransitionend
, etc...
bindEvent( HTMLElement, type, listener[, options] );
bindEvent( HTMLElement, type, listener[, useCapture] );
The Element object you want bind for.
The same as EventTarget.addEventListener()
, read more at MDN.