简体   繁体   English

从左到右动画宽度

[英]Animate width left to right

I am trying to find a way to animate a div using jQuery to shrink the width from left to right. 我试图找到一种方法来使用jQuery的div动画以将宽度从左向右缩小。

I have the element on click at first: 我首先要点击一下元素:

  • slide in from left to right 从左向右滑入
  • then have it continue to the right off my div, like it just keeps moving off the page, comes in and click again comes off. 然后让它继续在我的div右边继续前进,就像它一直在离开页面一样,进入并再次单击退出。 I have the toggle function in and working properly, but I am not sure how to make it keep moving off the page. 我具有切换功能并且可以正常工作,但是我不确定如何使它保持离开页面的状态。

Any ideas? 有任何想法吗?

Shrink it right to left (like you know how to), but simultaneously increase the left position style, or the left margin. 将其从右向左缩小(如您所知),但同时增加左位置样式或左边界。

Something like: 就像是:

var distance = $("div").css("width");

$("div").animate({
"width": "0",
"marginLeft": distance
});

you need to set the margin property. 您需要设置margin属性。 But you'll also want to position it absolutely if there's any elements either side of it. 但是,如果它的两侧都有任何元素,则也要绝对定位它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM