It's currently late 2015, and the situation has changed slightly. First of all, McBrainy's comment about capitalization above is important. The webkit
prefix is now Webkit
, but luckily only used by Safari at this point. Both Chrome and Firefox support el.style.transform
without the prefix now, and I think IE does as well. Below is a slightly more modern solution for the task at hand. It first checks to see if we even need to prefix our transform property:
var transformProp = (function(){
var testEl = document.createElement('div');
if(testEl.style.transform == null) {
var vendors = ['Webkit', 'Moz', 'ms'];
for(var vendor in vendors) {
if(testEl.style[ vendors[vendor] + 'Transform' ] !== undefined) {
return vendors[vendor] + 'Transform';
}
}
}
return 'transform';
})();
Afterwards, we can just use a simple one-liner call to update the transform
property on an element:
myElement.style[transformProp] = 'translate3d(0,' + dynamicY + 'px,0)';
Transform
instead oftransform
). I discovered this the hard way... – Agneta