在 jQuery 中转换
我正在尝试使用 jquery 获取一个元素来设置旋转悬停效果的动画,我有这个 jsFiddle进行测试。到目前为止我有这个:
$(".icon").hover(function() {
$(this).stop().animate({transform: "rotate(-90deg)", height: "200px"},400);
},function() {
$(this).stop().animate({backgroundColor : "black", color: "red"},400);
});
但它似乎根本没有旋转它,我意识到设置 css 的正确方法是:
-webkit-transform:rotate(30deg);
我已经尝试过:
$(this).stop().animate({-webkit-transform: "rotate(-90deg)", height: "200px"},400);
但即使高度也没有改变。任何建议都会有帮助谢谢!
I'm trying to get an element to animate a rotation hover effect using jquery, I have this jsFiddle going to test. So Far I have this:
$(".icon").hover(function() {
$(this).stop().animate({transform: "rotate(-90deg)", height: "200px"},400);
},function() {
$(this).stop().animate({backgroundColor : "black", color: "red"},400);
});
But it doesn't seem to be rotating it at all, I realize the proper way to set the css is:
-webkit-transform: rotate(30deg);
I've tried this:
$(this).stop().animate({-webkit-transform: "rotate(-90deg)", height: "200px"},400);
but then even the Height doesn't change. any advice would help thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您使用 jquery,jquery.transit 是非常简单且功能强大的库,它允许您进行转换,同时为您处理跨浏览器兼容性。
它可以像这样简单:$("#element").transition({x:'90px'})。从此链接获取:http://ricostacruz.com/jquery.transit/
If you're using jquery, jquery.transit is very simple and powerful lib that allows you to make your transformation while handling cross-browser compability for you.
It can be as simple as this : $("#element").transition({x:'90px'}). Take it from this link : http://ricostacruz.com/jquery.transit/
jquery.transform.js是Louis remi开发的jquery 2d转换插件。它允许像 jquery 中的 css 一样使用转换。请访问此链接获取有关如何使用它的一些说明。使用此插件旋转元素的简单说明如下:
jquery.transform.js is a jquery 2d transform plugin developed by Louis remi. it allows to use transform like css in jquery. visit this link for some illustrations on how to use it. A simple illustration to rotate an element using this plugin is as follows:
除了 IE9 之外,所有支持转换的浏览器也都支持转换,所以你最好不要像这样使用 JS:
示例: http://jsfiddle.net/9CYET/14/
(我知道这不是您想要的所有属性,但您明白了!如果您还想更改高度,则需要设置这将原点变换到正确的位置)。
在 IE9 中,旋转时不会有动画,而在较旧的浏览器中则不会发生任何情况。您可以修改 IE 的过滤器,以便在真正旧的 IE 中进行轮换。
Apart from IE9, all browsers that support transform also support transition, so you might be better off doing it without JS like this:
Example: http://jsfiddle.net/9CYET/14/
(I know it's not all the properties you wanted, but you get the idea! If you want to change height as well you'll need to set the transform-origin to the right place).
In IE9 that will rotate with no animation, and in older browsers nothing will happen. You could hack around with the filters for IE to get rotation in the really old IEs as well.
使用优秀的 jQuery Rotate 插件。 http://code.google.com/p/jqueryrotate/。所有主流浏览器都支持
要旋转图像,您需要做的就是
$('#myImage').rotate(30) //for a 30 Degree spin
其中
#myImage
是要旋转的元素的 id。要设置旋转动画,您可以使用 setTmeout ex:
Use the excellent jQuery Rotate plugin. http://code.google.com/p/jqueryrotate/. It is supported by all major browsers
To rotate an image, All you need to do is
$('#myImage').rotate(30) //for a 30 degree rotation
Where
#myImage
is the id of the element you want rotated.To animate rotation, you can use setTmeout ex:
跨浏览器应用 CSS 转换的最佳 jquery 插件是 jquery transform。
它还可以制作动画,并且可以在 Github 上找到,并附有详细的文档。
The best jquery plugin to apply CSS transform across browser is jquery transform.
It can also do animations and is available on Github with a detailed documentation.
可能这篇文章有点过时了,但你不需要额外的插件(这是如果你不希望支持 IE 8 及以下版本)。
我已经按以下方式进行了整理:
1)在 HTML 的 CSS 中定义转换时间:
然后在您的脚本中执行:
这在 Chrome 中对我有用、Firefox 和 Safari,我没有测试 IE,但它应该可以在 IE9 及更高版本中工作。
Probably the post is a bit outdated, but you do not need an additional plugin (this is if you do not wish to support IE 8 and below).
I have sorted it out in the next way:
1) In the CSS of the HTML define the time of transformation:
Then in your script do:
This worked for me in Chrome, Firefox and Safari, I did not test it IE, but it should work in IE9 and greater.
jQuery animate 不支持旋转(请参阅 http://bugs.jquery.com/ticket/4171 和 jQuery 文档)
此外,animate 仅支持带有数值的 CSS,这意味着动画颜色也不起作用。糟糕,我不知道 jQuery UI 添加了对颜色的支持。jQuery animate doesn't support rotation (see http://bugs.jquery.com/ticket/4171 and the jQuery documentation)
Also, only CSS with numerical values are supported for animate, meaning animating colors won't work either.Oops, was not aware jQuery UI added support for colors.如果你想在 css 中对某些内容进行动画处理,你只需设置“transitionDuration”css 属性(不需要 jQuery.animate),例如:
但是,这仅在现代浏览器中有效,因此你必须使用 jQuery.animate 作为后备。
这是处理此问题的 jQuery 插件:
https://github.com/benbarnett/jQuery-Animate-Enhanced
它只是重写 jQuery.animate 函数以使用 css 动画(如果可用),因此您不必担心跨浏览器问题,只需调用 jQuery.animate 即可调用最佳可用方法。
If you want to animate something in css, you just have to set "transitionDuration" css property(no need for jQuery.animate), for example:
However this will work only in modern browsers, so you have to use jQuery.animate as fallback.
Here is jQuery plugin which handling this:
https://github.com/benbarnett/jQuery-Animate-Enhanced
It just overrides jQuery.animate function to use css animation if available, so you don't have to worry about cross browser issues, just call jQuery.animate and the best available method will be called.
我用这个来衡量:
I used this for scale: