连续旋转图像

发布于 2024-12-03 14:59:42 字数 1424 浏览 3 评论 0原文

我想在我的网站上放置旋转徽标。我的意思是它应该不断旋转。我尝试过用 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>

它不起作用。请任何人帮助我

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-12-10 14:59:42

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

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

咆哮 2024-12-10 14:59:42

我不确定代码本身是否存在错误,或者它是否只是没有启动,但我要尝试的第一件事是将函数调用移动到文档就绪侦听器...

尝试:

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

而不是仅仅

rotation();

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文