12

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 Explorer 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!

kthornbloom
  • 3,660
  • 2
  • 31
  • 46
  • 1
    Maybe show some code and/or image examples. If compatibility is important, have you considered using an animated GIF? – Pekka Feb 17 '11 at 17:06
  • 2
    Have you thought of using an animated GIF for the wheel? – Lazarus Feb 17 '11 at 17:07
  • I'm speculating that the rotation of the wheel should sorta match the movement of the road, and thusly it would be nice to have some JavaScript variables to work with that would allow these to sync up. Is that a fair guess, @KThornbloom? – MrBoJangles Feb 17 '11 at 17:38

7 Answers7

13

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();
Kaos
  • 754
  • 1
  • 8
  • 13
6

Check out my post:

enter image description here

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
4

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.

MrBoJangles
  • 12,127
  • 17
  • 61
  • 79
  • Thanks! Looks like that's the key, and Sarfraz down there has examples for me to look at with that code. – kthornbloom Feb 17 '11 at 17:39
  • True that. For what it's worth, his code contains `setInterval()`. And it's way nifty. – MrBoJangles Feb 17 '11 at 17:41
  • Hmm, I'm still a little confused. Sarfraz's method only works once you click on it, and only rotates once although the title of the blog says "continuous rotation". Maybe I'm missing something? – kthornbloom Feb 17 '11 at 18:47
  • It is the conditional that is in Sarfraz' code, if (counter != -360) {...}. Once that is no longer true, it stops a-rotatin'. Just for completeness, I might add an else statement to clearInterval() at that point. – MrBoJangles Feb 17 '11 at 20:02
1

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...

Community
  • 1
  • 1
Stobor
  • 44,246
  • 6
  • 66
  • 69
  • Thanks for the suggestion. The reason I didn't go for an animated gif is because I wanted the animation to be nice and smooth, and also to be able to easily control the speed. – kthornbloom Feb 17 '11 at 17:38
0

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/

Ernest Marcinko
  • 405
  • 3
  • 12
0

@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.

Community
  • 1
  • 1
vyrp
  • 890
  • 7
  • 15
0

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

pic360 plugin

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226