1

我想在我的网站上放置旋转徽标。我的意思是它应该不断地旋转。我试过用 jquery 做这样的事情。请看一下并建议我哪里出错了。为什么这段代码不起作用。请帮我

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

我像这样在我的html中使用了这段代码

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

它不工作。请任何人帮助我

4

2 回答 2

5

jQuery 没有 .rotate() 函数。我认为您的意思是要包括jQuery Rotate 插件

于 2011-09-06T19:39:26.777 回答
0

我不确定它自己的代码中是否存在错误,或者它是否只是没有启动,但我首先要尝试的是移动函数调用以旋转到文档就绪侦听器......

尝试:

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

而不仅仅是

rotation();

问题可能是当此函数执行时,您尝试操作的图像实际上并未加载到 dom 中。将其移动到文档就绪回调将确保 dom 在执行之前完全加载。

于 2011-09-06T19:39:49.313 回答