Skip to content

Instantly share code, notes, and snippets.

@eklimcz-zz
Created July 25, 2011 18:28
Show Gist options
  • Save eklimcz-zz/1104800 to your computer and use it in GitHub Desktop.
Save eklimcz-zz/1104800 to your computer and use it in GitHub Desktop.
css3d Transform helper
/*--------------------
Usage:
if (Modernizr.csstransforms3d) {
this.set3dTransform(this.scroller, xValue + "px", yValue + "px");
this.set3dTransform(this.parallaxBg, xValue/12 + "px", 0 + "px");
}
else{
this.set2dTransform(this.scroller, xVAlue + "px", yValue + "px");
this.set2dTransform(this.parallaxBg, xVAlue / 12 + "px", yValue + "px");
}
*/-------------------
this.set2dTransform = function(ele, x, y) {
var v = "translate(" + x + "," + y + ")";
ele.style.transform = v;
ele.style.WebkitTransform = v;
ele.style.msTransform = v;
ele.style.MozTransform = v;
}
this.set3dTransform = function(ele, x, y) {
var v = "translate3d(" + x + "," + y + ", 0px)";
ele.style.transform = v;
ele.style.WebkitTransform = v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment