How would I rotate an element with a jQuery's .animate()? I'm using the line below, which is currently animating the opacity correctly, but does this support CSS3 transforms?

$(element).animate({
   opacity: 0.25,
   MozTransform: 'rotate(-' + -amount + 'deg)',
   transform: 'rotate(' + -amount + 'deg)'
});

推荐答案

据我所知,基本动画无法为非数字CSS属性设置动画.

I believe you could get this done using a step function and the appropriate css3 transform for the users browser. CSS3 transform is a bit tricky to cover all your browsers in (IE6 you need to use the Matrix filter, for instance).

EDIT:这里有一个在webkit浏览器(Chrome、Safari)中工作的示例:http://jsfiddle.net/ryleyb/ERRmd/

If you wanted to support IE9 only, you could use transform instead of -webkit-transform, or -moz-transform would support FireFox.

The trick used is to animate a CSS property we don't care about (text-indent) and then use its value in a step function to do the rotation:

$('#foo').animate(
..
step: function(now,fx) {
  $(this).css('-webkit-transform','rotate('+now+'deg)'); 
}
...

Jquery相关问答推荐

Django BaseDataTableView-Filter_queryset方法不起作用

多个 AJAX 调用;获取所有失败的呼叫

为什么函数没有进入

:eq Jquery,我似乎无法显示第一个之后的元素

使用带有 Ajax GET URL 的数组在每次单击按钮时一次单步执行一个

Jquery each - 停止循环并返回对象

$.each() 与 for() 循环 - 和性能

jQuery Mobile:动态添加内容的标记增强

如何判断是否有任何 JavaScript 事件侦听器/处理程序附加到元素/文档?

JSON字符串到JS对象

用jquery查找div底部的位置

将参数附加到 URL 而不刷新

Select 除第一个之外的所有子元素

如何使用 jQuery 更改文本

我想了解 jQuery 插件语法

如何获得元素的正确偏移量? - jQuery

Url.Action 在我的 url 中放了一个 &,我该如何解决这个问题?

检测 jQuery UI 对话框是否打开

如何淡出显示:inline-block

jquery追加到列表的前面/顶部