Skip to content

Simple tool to toggle classes based on events specified in html element attributes

License

Notifications You must be signed in to change notification settings

very-random-man/autobind.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Autobind.js

This is a really simple bit of jQuery code I created to make it super-easy to facilitate CSS transitions from user interactions. You just add some attributes to HTML elements to describe the behaviour and classes will be toggled on specified elements based on events, such as click or hover.

See example here: https://very-random-man.github.io/autobind.js/example.html

How to set up

Just add the script in the HEAD tag, after jQuery has been included.

<script src="js/autobind.js"></script>

How to control behaviour

Use data-autobind attributes to specify behaviour on html elements.

Set the event you want to capture. You can add more than one event if you want.

data-autobind="click"
data-autobind="mouseenter mouseleave"

If you want to prevent default behaviour, such as stopping links working on <a> tags. Only its presence is required so the value can be nothing or anything.

data-autobind-prevent

Set the class or classes that are toggled when the event is triggered.

data-autobind-classes="animated"
data-autobind-classes="expanded collapsed"

Specify an optional selector if you want to toggle classes on a different element or collection of elements elsewhere in the document.

data-autobind-selector="body"

About

Simple tool to toggle classes based on events specified in html element attributes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published