Skip to content

Instantly share code, notes, and snippets.

@josephdburdick
Created September 7, 2016 15:32
Show Gist options
  • Save josephdburdick/13d9895b6855644c2a6a06ad5e9910a6 to your computer and use it in GitHub Desktop.
Save josephdburdick/13d9895b6855644c2a6a06ad5e9910a6 to your computer and use it in GitHub Desktop.
Cross-browser transform translate3d in Javascript
function getSupportedPropertyName(properties) {
for (var i = 0; i < properties.length; i++) {
if (typeof document.body.style[properties[i]] != "undefined") {
return properties[i];
}
}
return null;
}
var transform = ["transform", "msTransform", "webkitTransform", "mozTransform", "oTransform"];
var item = document.querySelector("#theItem");
var transformProperty = getSupportedPropertyName(transform);
if (transformProperty) {
item.style[transformProperty] = translate3d(someValueX, someValueY, 0px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment