Important facts about commercial licenses

  • Licenses are perpetual. They do not expire and do not need to be renewed.
  • Licenses can be upgraded. You can upgrade to a more expensive license later paying only the difference in cost.
  • Pay attention to the distribution type - Hosted (sites / servers), binary (applications) or source (includes all the others). Choose according to your needs (more below).
  • All licenses allow commercial use unless otherwise indicated.
  • Read the full license by clicking on the icon.
  • Read more about licenses in our handy license guide.
$19

MIT license

The MIT license is an
open-source license.
You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

  • Released: Feb 25, 2011
    Last Update: May 10, 2012
  • Language: JavaScript
    Framework: jQuery
  • Time / costs savings: 50h / $3000 *
(1 ratings)

jQuery 2d transform

jQuery 2d transform
Developed by Louis-Rémi Babé, Released Feb 25, 2011

A jQuery cssHooks adding cross-browser 2d transform capabilities to $.fn.css() and $.fn.animate()

JavaScript

Tags: css3 , ie , jquery , polyfill

With this jQuery transform plugin you will be able to:

  • rotate any element
  • scale an element as well as its text content
  • translate elements in an efficient way*
  • skew elements

The elements can be transformed instantly or the transformation can be animated, using the standard jQuery css() and animate() functions:

$('div.test').css( 'transform', 'rotate(10deg)' );

$('div.test').animate({
  transform: 'translateX(100px) translateY(50px) scale(2) rotate(90deg)'
});

It is the lightest, cleanest and most efficient plugin to achieve 2d transformation in a cross-browser way.

* no content reflow in modern browsers

Back to top

Documentation

jquery.transform2d.js adds 2d transform capabilities to jQuery css() and animate() functions.

Usage:

Set transform with a string

$('#myDiv').css('transform', 'translate(50px, 30px) rotate(25deg) scale(2,.5) skew(-35deg)');
$('#myDiv').animate({transform: 'translateY(-100px) rotate(1rad) scaleX(2) skewY(42deg)'});

You can use the following list of transform components:

  • translateX(<number>px)
  • translateY(<number>px)
  • combined: translate(<number>px, <number>px) the second number is optional and defaults to 0
  • scaleX(<number>)
  • scaleY(<number>)
  • combined: scale(<number>, <number>) the second number is optional and defaults to the value of the first one
  • rotate(<angle>) units for angles are *rad (default), deg or grad.*
  • skew(<angle>)
  • skew(<angle>)
  • combined: skew(<angle>, <angle>) the second angle is optional and defaults to 0
  • matrix(<number>, <number>, <number>, <number>, <number>, <number>)*

*matrix gives you more control about the resulting transformation, using a matrix construction set.
When using it in animations however, it makes it impossible to predict how the current and target transformations are going to be interpolated; there is no way to tell whether elements are going to rotate clockwise or anti-clockwise for instance.

Get transform

returns a computed transform matrix.

$('#myDiv').css('transform') == 'matrix(0,1,-1,0,100,50)';

Limitations:

  • requires jQuery 1.4.3+,
  • Should you use the translate property, then your elements need to be absolutely positioned in a relatively positioned wrapper or it will fail in IE,
  • transformOrigin is not accessible.

Why such restrictions with 'translate'?

Since translate is unavailable in IE<9, we have to emulate it using top and left properties of the element style.
This can, of course, only work if the elements are absolutely positioned in a relatively positioned wrapper.

Other plugins position the elements and wrap them transparently.
I think that transparently messing with the DOM often introduces unpredictable behavior.
Unpredictable behavior leads developers to fear plugins.
Fear leads to anger. Anger leads to hate. Hate leads to suffering.
I prefer leaving this up to you.

License

Dual licensed under GPL and MIT licenses.

Copyright (c) 2010 Louis-Rémi Babé.

View all 1 reviews »

User Reviews

  • 2 of 2 people found this review helpful Stevan Zivadinovic 10 months ago
    HoboLobo.net wouldn't be the same without it.

    This is the best plugin of its kind. I tried great many before I settled with this one. The primary selling point has to be that it doesn't replace the CSS spec, but extends it. It simply makes JQuery transformations behave like one expects them to.

    It has saved me a whole mess of time in the last year that I have been using it. Had it not already existed, I would've basically had to make it myself. When I noticed that the updates have moved to Binpress, I pulled out my wallet with no hesitation.
    Flag
    Was this helpful? Yes No
Read all 1 comments »

Questions & Comments


Or enter your name and Email
  • Brian Kawooya 1 month ago
    This script works well, but I do have a big issue. I have a div that has child elements(h1, img) that are absolutely positioned. When I rotate the parent div everything inside of it rotates but in IE8 they don't, on the parent div rotates. The only way everything rotates is only when those child elements aren't absolutely or relatively positioned. Any suggestions?
You must be logged-in to vote. Log-in to your account or register now.