[英]jQuery animate width to the right
I want to animate div to slide to the right like the example below: 我想动画div滑动到右边,如下例所示:
http://jsfiddle.net/56hxy/3/ http://jsfiddle.net/56hxy/3/
but instead of shifting the margin, I want to "squish" the width but it's not working by changing the width % ( width: '60%'
) it squishes to the left instead.. 但是我没有移动边距,而是想要“挤压”宽度,但是通过更改宽度%(
width: '60%'
)而不是工作,而是向左移动。
Not sure if this is exactly what you're looking for but try: 不确定这是否正是您正在寻找的但是尝试:
$('#content').animate({
marginLeft: '40%',
width:'60%'
});
Or give right:0
to #content
in the CSS, then you can animate the width
and it will shrink from left to right without requiring margins. 或者
right:0
在CSS中使用right:0
到#content
,然后你可以设置width
动画,它将从左到右缩小而不需要边距。 Same effect as the above but cleaner. 与上述相同,但更清洁。 Fiddle
小提琴
Also, jQuery has a built-in " toggle event " for alternating clicks so, if you're toggling just the click event you can use: 此外,jQuery还有一个内置的“ 切换事件 ”,用于交替点击,因此,如果您只是切换可以使用的点击事件:
$('#content').toggle(function() {
$(this).animate({ width:'60%' });
}, function() {
$(this).animate({ width:'100%' });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.