Created
August 15, 2013 00:09
-
-
Save mrmartineau/6237080 to your computer and use it in GitHub Desktop.
Simple shim to make getting and setting CSS values more easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get/Set CSS styles with ease | |
function styler(el) { | |
return { | |
/* Get CSS style | |
* @prop : String - CSS property name e.g 'width', 'height' | |
* @int : Boolean | |
*/ | |
get : function(prop, int) { | |
/* TODO: | |
* Get multiple CSS properties. prop could be comma separated list | |
* Allow get all css values | |
* Throw errors when args not in correct format | |
*/ | |
var int = int || false; | |
if (int === true) { | |
return parseInt(window.getComputedStyle(el, null).getPropertyValue(prop), 10); | |
} else{ | |
return window.getComputedStyle(el, null).getPropertyValue(prop); | |
} | |
}, | |
/* Set CSS style | |
* @prop : String - CSS property name e.g 'width', 'height' | |
* @val : String - CSS property value e.g. '200px' | |
*/ | |
set : function(prop, val) { | |
/* TODO: | |
* Set multiple CSS properties. prop could be comma separated list | |
* Throw errors when args not in correct format | |
*/ | |
return el.style[prop] = val; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment