如何使用 jquery 不断旋转对象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5032094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:25:02  来源:igfitidea点击:

How to CONSTANTLY rotate an object with jquery?

jqueryimagewebcssrotation

提问by kthornbloom

OKAY! Here's the situation. I've got a jQuery plugin that's animating a background-image in my header to constantly scroll left-to-right. I have a .png of a wheel sitting on this header. I need to have the wheel constantly spinning with the moving background.

好的!这是情况。我有一个 jQuery 插件,它在我的标题中为背景图像设置动画以不断从左到右滚动。我有一个 .png 的轮子坐在这个标题上。我需要让轮子随着移动的背景不断旋转。

CSS3- Yes I could use CSS3, but then some poor soul using Internet Explorer would see a stationary wheel on a moving background which would be weird.

CSS3- 是的,我可以使用 CSS3,但是一些使用 Internet Explorer 的可怜人会在移动的背景上看到一个固定的轮子,这会很奇怪。

jQuery Plugins- This is what I'd LIKE to use, but I have yet to find one that will constantly rotate the image. Most only rotate by a certain angle when you activate it.

jQuery 插件——这是我想要使用的,但我还没有找到一个可以不断旋转图像的插件。大多数仅在您激活它时旋转特定角度。

If anybody has any thoughts, I'd appreciate it!

如果有人有任何想法,我将不胜感激!

回答by Kaos

You could try this:

你可以试试这个:

http://code.google.com/p/jqueryrotate/wiki/Examples

http://code.google.com/p/jqueryrotate/wiki/Examples

    var rotation = function (){
   $("#img").rotate({
      angle:0, 
      animateTo:360, 
      callback: rotation,
      easing: function (x,t,b,c,d){        // t: current time, b: begInnIng value, c: change In value, d: duration
          return c*(t/d)+b;
      }
   });
}
rotation();

回答by MrBoJangles

It's not jQuery as such, but if you want to do something constantly in JavaScript, use setInterval(), like so:

它不是 jQuery,但如果您想在 JavaScript 中不断地做一些事情,请使用setInterval(),如下所示:

setInterval("alert('Rotate!');", 100);

But replace the alert with your rotation code, and the interval is in milliseconds.

但是将警报替换为您的轮换代码,间隔以毫秒为单位。

回答by Stobor

It looks like you want this answer to a related question about rotating images with jQuery...

看起来你想要这个关于使用 jQuery 旋转图像的相关问题的答案......

But it's purely a rotating wheel, then a two or three frame animated gif will probably be easier, faster, and less CPU-intensive...

但它纯粹是一个旋转的轮子,那么两帧或三帧的动画 gif 可能会更容易、更快、CPU 密集程度更低……

回答by Somnath Muluk

You can use jquery plugin for rotating image like 3d object:

您可以使用 jquery 插件来旋转图像,如 3d 对象:

pic360 plugin

pic360 插件

回答by Ernest Marcinko

I have created a plugin for this, which works with internet explorer 7 and 8 as well! Here you go: http://wp-dreams.com/jquery-element-rotation-plugin/

我为此创建了一个插件,它也适用于 Internet Explorer 7 和 8!给你:http: //wp-dreams.com/jquery-element-rotation-plugin/

回答by vyrp

@dietbacon asked how to stop a rotation. Since I cannot yet comment, I will answer here.

@dietbacon 询问如何停止轮换。由于我还不能发表评论,我将在这里回答。

In thisanswer, I wrote a function that does an infinite rotation in a given element and that can be cancelled.

这个答案中,我编写了一个函数,该函数在给定元素中进行无限旋转并且可以取消。