Created
July 22, 2015 01:56
-
-
Save julienetie/e80f9759113bfb61cf35 to your computer and use it in GitHub Desktop.
Styles an element with a vendor prefix if required.
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
/** | |
* @author Julien Etienne | |
* Sets the style of an element with the appropriate browser prefix. | |
* @param {Object} styleObject - Style detials. | |
* @param {Object} styleObject.el - The element to apply the style to. | |
* @param {String} styleObject.style - The style that may require a prefix. | |
* @param {String|Number} styleObject.value - The value to be applied. | |
*/ | |
function stylePrefix(styleObject) { | |
var element = styleObject.el, | |
cssStyle = styleObject.style, | |
value = styleObject.value; | |
if (!element && !cssStyle && !value) { | |
return; | |
} | |
var vendors = ['ms', 'o', 'moz', 'webkit'], | |
cssStyleCap = cssStyle.charAt(0).toUpperCase() + cssStyle.substring(1); | |
if (!element.style.cssStyle) { | |
vendors.filter(function(vendor) { | |
if (element.style[vendor + cssStyleCap] !== undefined) { | |
element.style[vendor + cssStyleCap] = value; | |
} | |
}); | |
} else { | |
element.style.cssStyle = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment