我怎样才能以相反的方式制作动画?
您好,
我正在更改用作 bar 的元素的宽度,并且有效。然而我不能 使它朝相反的方向动画。我尝试将 - 放在 bar_width 前面,但无济于事。宽度将动态计算,只是我希望方向向左而不是向右,就像这样 <-------- 不是 ---------->
var bar_width=$(this).css('width') ;
$(this).css('width', '0').animate({ width: bar_width }, queue:false,duration:3500,easing: easing});
Greetings,
I am changing the width of an element which serves as a bar , and that works. However I can't
make it so that it animates it in the opposite direction. I tried putting - in front of bar_width but to no avail. Width will be dynamically calculated it's just that I want the direction to go to the left rather than to the right like so <------- not ----------->
var bar_width=$(this).css('width') ;
$(this).css('width', '0').animate({ width: bar_width }, queue:false,duration:3500,easing: easing});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过同时设置元素的
margin-left
和width
动画来从右向左设置动画:CSS
jQuery
在此处执行。
或者,如果您的元素是绝对定位的,您可以为
left
属性和width
同时。You could animate it from right to left by animating both the
margin-left
andwidth
of the element at the same time:CSS
jQuery
In action here.
Alternative, if your element is positioned absolutely you could animate the
left
property andwidth
at the same time.您可以使用
"toggle"
作为参数,而不是0
,如下所示:"toggle"
将从其全宽度动画到0
,下次则相反。Instead of
0
you can use"toggle"
as the parameter, like this:"toggle"
will animate from it's full width to0
, and the reverse next time.