I'm trying to animate a div, and get it to rotate about the y-axis 180 degrees. When I call the following code I get a jQuery error:
$("#my_div").animate({
"transform": "rotateY(180deg)",
"-webkit-transform": "rotateY(180deg)",
"-moz-transform": "rotateY(180deg)"
}, 500, function() {
// Callback stuff here
});
});
It says "Uncaught TypeError: Cannot read property 'defaultView' of undefined" and says it's in the jQuery file itself... what am I doing wrong?
You can also predefine the rotation in a CSS class and use jQuery to add/remove the class:
CSS:
jQuery:
Try this:
http://jsfiddle.net/RPSzb/2/
Forget about jQuery's
$.animate()
, instead use$.velocity()
. Velocity.js is an animation extention of jQuery. It uses the same syntax as jQuery and allows you to animate CSS3 such as 3D transforms, translates, rotates, colour fading, transitions, skews, ... Anything you want. And since it is smart enough to use CSS3 instead of JS where possible, it animates with a better performance aswell. I don't understand why jQuery doesn't do this yet!http://julian.com/research/velocity/
jQuery cannot animate transform properties out of the box. But you can animate custom properties with
.animate()
and do the transformation "manually" using thestep
function:See this fiddle for a working example (click on the blue box).
This is similar to undefined's answer but it doesn't abuse a real CSS property.
Note: The name of the custom property should be a jQuery.camelCase() name since
.animate()
uses the camelCased names internally and therefore, will store the current value of the property using the camelCased name and thefx.prop
will also be the camelCased name.