From db817765d3bf42eefe7fd3e3aa0806ddf1950f07 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 12 Mar 2018 22:01:31 +0200 Subject: [PATCH] Update prefix.md --- snippets/prefix.md | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/snippets/prefix.md b/snippets/prefix.md index 45e28a598..e6b53ece1 100644 --- a/snippets/prefix.md +++ b/snippets/prefix.md @@ -2,27 +2,22 @@ Returns the prefixed version (if necessary) of a CSS property that the browser supports. -Use an array of vendor prefix strings and loop through them, testing if `document.body` has one -of them defined in its CSSStyleDeclaration object, otherwise return `null`. Use `String.charAt()` -and `String.toUpperCase()` to capitalize the property, which will be appended to the vendor prefix string. +Use an array of vendor prefix strings and loop through them, testing if `document.body` has one of them defined in its `CSSStyleDeclaration` object, otherwise return `null`. +Use `String.charAt()` and `String.toUpperCase()` to capitalize the property, which will be appended to the vendor prefix string. ```js const prefix = property => { - const prefixes = ['', 'webkit', 'moz', 'ms', 'o'] - const upperProp = property.charAt(0).toUpperCase() + property.slice(1) + const prefixes = ['', 'webkit', 'moz', 'ms', 'o']; + const upperProp = property.charAt(0).toUpperCase() + property.slice(1); for (let i = 0; i < prefixes.length; i++) { - const prefix = prefixes[i] - const prefixedProp = prefix ? prefix + upperProp : property - if (typeof document.body.style[prefixedProp] !== 'undefined') { - return prefixedProp - } + const prefix = prefixes[i]; + const prefixedProp = prefix ? prefix + upperProp : property; + if (typeof document.body.style[prefixedProp] !== 'undefined') return prefixedProp; } - return null + return null; } ``` ```js -prefix('transform') -// 'transform' on a supported browser -// otherwise 'webkitTransform' or 'mozTransform' or 'msTransform' or 'oTransform' +prefix('transform'); // 'transform' on a supported browser, otherwise 'webkitTransform' or 'mozTransform' or 'msTransform' or 'oTransform' ```