有人可以解释一下这段 jQuery 代码吗?
此代码取自 http://wilq32.googlepages.com/wilq32.rollimage222,并且应该为图像旋转设置动画。
我无法准确地弄清楚结构,以及如何训练它来做我想要的事情,例如 - 让 div X 在悬停时旋转 div Y (而不是旋转本身),或者添加其他功能,例如淡入淡出到动画。
$(document).ready(function()
{
var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
bind:
[
{"mouseover":function(){rot[0].rotateAnimation(85);}},
{"mouseout":function(){rot[0].rotateAnimation(-35);}}
]
});
});
提前致谢
This code is taken from http://wilq32.googlepages.com/wilq32.rollimage222, and is supposed to animate an image rotation.
I can't figure out the structure exactly, and how to train it to do what I want, for example - make div X rotate div Y on hover (instead of rotating itself), or adding other functions such as fade to the animation.
$(document).ready(function()
{
var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
bind:
[
{"mouseover":function(){rot[0].rotateAnimation(85);}},
{"mouseout":function(){rot[0].rotateAnimation(-35);}}
]
});
});
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是它的作用。
1) 等待页面加载 $(document).ready()
2) 将“rot”指定为等于 jQuery.rotate 对象。
3) 然后将该对象绑定到两个不同的事件,mouseover 和 mouseout。绑定意味着当这些事件触发时将执行该代码段。
鼠标悬停启动“rotateAnimation(85)”,鼠标悬停设置相同的功能-35。我猜它会反转它所看到的图像的旋转。
要将内容添加到轮换中,您可以这样做。
希望有帮助。
Here's what it does.
1) Waits for page load $(document).ready()
2) Assigns "rot" to equal a jQuery.rotate object.
3) This object is then bound to two different events, mouseover, and mouseout. Binding means that when those events trigger that piece of code will execute.
Mouseover starts "rotateAnimation(85)" and mouseout sets the same function -35. I'm guessing that it reverses the rotation of the image it's looking at.
To add things to the rotation, you could just do this.
Hope that helps.
根据文档的绑定参数特定于rotateimage 对象。相反,我认为您只想在事件触发时使用旋转功能。
The bind parameter according to the docs is specific to the rotateimage object. Instead I think you just want to use the rotate function when your event fires off.
var rot
保存对'#image3'
的引用。然后旋转限制为逆时针 55 度和顺时针 25 度。此时尚未发生任何用户可见的操作。 #image3 能够接收旋转动画命令。然后绑定部分获取包含两个要绑定的对象的数组的内容。第一个绑定 #image3 的
mouseover
,这样它将触发对旋转rot[0]
的调用,旋转本身就是顺时针 85 度。它不会移动 85 度,而是受到之前设置的限制,只能移动到 25 度。第二个通过绑定
mouseout
执行类似的操作,以便它将逆时针移动到 35 度,并且此移动不受minAngle
限制。var rot
holds a reference to'#image3'
. Then rotation is given limits of 55 degrees counter clockwise and 25 degrees clockwise. No user visible action has taken place at this point. #image3 is enabled to receive rotateAnimation commands.Then the bind section takes the content of the array which holds two objects to bind. The first binds the
mouseover
of #image3 such that it will trigger a call to rotaterot[0]
, which is itself, 85 degrees clockwise. This does not travel 85 degrees, but is limited by the previous setting to only travel to 25 degrees.The second does a similar thing with binding
mouseout
so that it will travel to 35 degrees counter clockwise and this travel is not limited by theminAngle
.