{"id":389,"date":"2022-08-30T15:00:32","date_gmt":"2022-08-30T15:00:32","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/what-are-the-issues-with-getting-the-vendor-prefix-for-css-transitions-using-javascript-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:32","modified_gmt":"2022-08-30T15:00:32","slug":"what-are-the-issues-with-getting-the-vendor-prefix-for-css-transitions-using-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/what-are-the-issues-with-getting-the-vendor-prefix-for-css-transitions-using-javascript-collection-of-common-programming-errors\/","title":{"rendered":"What are the issues with getting the vendor prefix for CSS Transitions using javascript?-Collection of common programming errors"},"content":{"rendered":"<p>I don&#8217;t see anything wrong, but I would probably do it this way:<\/p>\n<pre><code>function getTransitionPrefix() {\n    var el = document.createElement( \"div\" ),\n        prefixes = [\"Webkit\", \"Moz\", \"O\", \"ms\"];\n    for ( var i = 0; i &lt; prefixes.length; i++ ) {\n        if ( prefixes[i] + \"Transition\" in el.style ) {\n            return prefixes[i];\n        }\n    }\n    return \"transition\" in el.style ? \"\" : false;\n}\n<\/code><\/pre>\n<p>Then setting the transition:<\/p>\n<pre><code>var setTransition = (function() {\n    var pref = getTransitionPrefix();\n    return function( elem, trans ) {\n        if ( pref !== false ) {\n            var s = pref === \"\" ? \"transition\" : pref + \"Transition\";\n            elem.style[s] = trans;\n        }\n    };\n})();\n\nsetTransition( element, \"transition settings\" );\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 18:41:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t see anything wrong, but I would probably do it this way: function getTransitionPrefix() { var el = document.createElement( &#8220;div&#8221; ), prefixes = [&#8220;Webkit&#8221;, &#8220;Moz&#8221;, &#8220;O&#8221;, &#8220;ms&#8221;]; for ( var i = 0; i &lt; prefixes.length; i++ ) { if ( prefixes[i] + &#8220;Transition&#8221; in el.style ) { return prefixes[i]; } } return &#8220;transition&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-389","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=389"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/389\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}