Skip to content

Bind event handler for all browsers by adding prefix automaticlly

License

Notifications You must be signed in to change notification settings

Diablohu/bind-event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Bind event handler for all browsers by adding prefix automaticlly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published