Bind event handler for all browsers by adding prefix automaticlly
JavaScript
Latest commit 2b404e7 Jan 9, 2017 @Diablohu get rid fo some ES6
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
package.json

README.md

bind-event

Bind event handler for all browsers by adding prefix automaticlly.

Install

npm install bind-event --save

Usage

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)
    }
)

result

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...

Options

bindEvent( HTMLElement, type, listener[, options] );
bindEvent( HTMLElement, type, listener[, useCapture] );

HTMLElement

The Element object you want bind for.

type, listener, options, useCapture

The same as EventTarget.addEventListener(), read more at MDN.