priya
priya

Reputation: 167

rotating an image continuously

I want to put rotating logo in my website. I mean it should be continuously rotating. I have tried doing like this with jquery. please have a look and suggest me where i am going wrong. Why this code is not working. Please help me

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();

I have used this code in my html like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script type="text/javascript" src="jquery.easing.1.3.js"></script>
<script type="text/javascript">
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();

</script>


<title>Untitled Document</title>
</head>

<body>


<img src="LMIH_LOGO.png" width="174" height="322" name="img" id="img" />
</body>
</html>

Its not working. Please anybody help me in this

Upvotes: 1

Views: 2674

Answers (2)

Rick Kukiela
Rick Kukiela

Reputation: 1264

I'm not sure if there is a bug within the code it self or if its just not starting, but my first thing to try would be to move the function call to rotate to the document ready listener...

Try:

$(document).ready(function() {
rotation();
});

instead of just

rotation();

The problem may be that the image you are trying to manipulate isnt actually loaded in the dom when this function executes. Moving it to the document ready callback will ensure the dom is fully loaded before executing.

Upvotes: 0

maxedison
maxedison

Reputation: 17553

jQuery does not have a .rotate() function. I think you mean to be including the jQuery Rotate plugin.

Upvotes: 5

Related Questions