Skip to content

mjc-gh/style.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

style.js

Light-Weight Javascript Style Wrapper

Installation

Using Bower:

bower install style.js

Or grab the source (minified).

Usage

Basic usage is as follows:

// Read a style
style(myHTMLElement)('font-size');

// Write a style
style(myHTMLElement)('font-size', '12px');

// Can write without pixel units
style(myHTMLElement)('font-size', 14);

// Can read without units too (returns a number)
style(myHTMLElement).unitless('font-size');
style(myHTMLElement).u('font-size'); // alias

// The Style function is also alised to S
S(myHTMLElement)('font-size', '2em');

// To remove a property, call with undefined
S(myHTMLElement)('font-size', undefined);

// Or with a CSS function
S(myHTMLElement)('transform', ['translate', '50%', '50%']);

Note that, the wrapper function will cache the computed styles. It will remove the cache when something is written. Do not set styles from elsewhere or else the cache will become invalid!

Contributing

We'll check out your contribution if you:

  • Provide a comprehensive suite of tests for your fork.
  • Have a clear and documented rationale for your changes.
  • Package these up in a pull request.

We'll do our best to help you out with any contribution issues you may have.

License

MIT. See LICENSE.txt in this directory.

About

Light-weight JavaScript Style Wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published