jQuery 如何为我的代码添加动画?
嘿,我现在知道一点 jQuery,但我仍然对动画有点困惑(特别是当我必须将它们添加到工作脚本中时)。
我有例如:
if (i = 1) {
i = i +1
$("#div p").css("left", "-" + width * i + "px");
}
如何动画()边距添加?我正在尝试、尝试、尝试……
if (i = 1) {
i = i +1
$("#div p").animate().css.("left", "-" + width * i + "px");
}
if (i = 1) {
i = i +1
$("#div p").css(.animate("left", "-" + width * i + "px"));
}
等等。
谢谢!
Hey, I know a little bit of jQuery now, but I'm still a bit confused with animations (especially when I have to add them to working script).
I have for example:
if (i = 1) {
i = i +1
$("#div p").css("left", "-" + width * i + "px");
}
How to animate() margin adding? I'm trying and trying and trying...
if (i = 1) {
i = i +1
$("#div p").animate().css.("left", "-" + width * i + "px");
}
if (i = 1) {
i = i +1
$("#div p").css(.animate("left", "-" + width * i + "px"));
}
etc.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以最简单的方式可以想象:
另外,当有疑问时,不要忘记查看官方文档:http ://api.jquery.com/animate/
In the easiest way imaginable:
Also, when in doubt, don't forget to take a look at the official documentation: http://api.jquery.com/animate/
你真的想要
.animate()
的边距吗?还是左边的位置?
(不需要
"px"
,因为这是两者的默认值。您也不需要"-"
两边的引号。您可以发送一个整数。)请记住,如果您要为左侧位置设置动画,则需要将 css 位置设置为
relative
或absolute.
编辑:
另请注意,在
if()
语句中,如果您尝试进行比较,则需要使用==
或 <代码>===,如:Do you actually want the margin to
.animate()
?Or the left position?
(No need for the
"px"
, since that is the default for both of these. You don't need the quotes around the"-"
either. You can send an integer.)Keep in mind that if you're animating the left position, you'll need to have your css position set to
relative
orabsolute
.EDIT:
Also note that in your
if()
statements, if you are trying to do a comparison, you need to use==
or===
, as in: