How to CONSTANTLY rotate an object with jquery?
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.
CSS3- Yes I could use CSS3, but then some poor soul using Internet Expl开发者_高级运维orer would see a stationary wheel on a moving background which would be weird.
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.
If anybody has any thoughts, I'd appreciate it!
You could try this:
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();
Check out my post:
- Rotate and Fly off elements with jQuery and CSS3
- See the DEMO
It's not jQuery as such, but if you want to do something constantly in JavaScript, use setInterval()
, like so:
setInterval("alert('Rotate!');", 100);
But replace the alert with your rotation code, and the interval is in milliseconds.
It looks like you want this answer to a related question about rotating images with 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...
You can use jquery plugin for rotating image like 3d object:
pic360 plugin
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/
@dietbacon asked how to stop a rotation. Since I cannot yet comment, I will answer here.
In this answer, I wrote a function that does an infinite rotation in a given element and that can be cancelled.
精彩评论