I am currently working on a function that animates elements on a webpage by adding inline styles to the elements. In its simplest form, it adds the following styles:
<div style="transition: transform 0.5s; transform: translateX(100px);">...</div>
However, I realized that I need to add support for older browsers. I decided to use Modernizer.prefixed
to find the correct prefixes for properties, but now I am encountering an issue with Safari.
Here is the code I tried to use:
var cssTransformProperty = Modernizr.prefixed("transform");
var cssTransitionProperty = Modernizr.prefixed("transition");
$myElement
.css(cssTransitionProperty, cssTransformProperty + " 0.5s")
.css(cssTransformProperty, "translateX(" + margin + "px)");
Unfortunately, when testing in Safari, it seems to be trying to add something like this:
.css("transition", "WebkitTransform 0.5s")
.css("WebkitTransform", "translateX(100px)")
The issue lies with "WebkitTransform 0.5s"
- Safari doesn't understand this line. Manually changing it to "-webkit-transform 0.5s"
resolves the problem.
Is there a way to instruct the prefixer to use this CSS format instead of the JavaScript one?