简体   繁体   English

队列宽度和高度在css3中转换

[英]Queue width and height transitions in css3

I want to be able to queue CSS3 width and height transitions. 我希望能够排队CSS3宽度和高度过渡。 When I click a div, its class is toggled by jquery to active , but I can't seem to get the width of the div to change first, and then the height. 当我单击一个div时,它的类被jquery切换为active ,但我似乎无法首先更改div的宽度,然后更改高度。

 $(document).ready(function() { $("#resize").click(function() { $("#resize").toggleClass("active"); }); }); 
 #resize.active { width: 100%; height: 300px; -webkit-transition-property: height, width; -webkit-transition-duration: 0.5s, 0.5s; -webkit-transition-delay: 0.5s, 0.5s; transition-property: height, width; transition-duration: 0.5s, 0.5s; transition-delay: 0.5s, 0.5s; } #resize { background-color: blue; height: 45px; width: 100px; -webkit-transition-property: width, height; -webkit-transition-duration: 0.5s, 0.5s; -webkit-transition-delay: 0.5s, 0.5s; transition-property: width, height; transition-duration: 0.5s, 0.5s; transition-delay: 0, 0.5s; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="resize"> <h1> Stuff </h1> </div> 

jFiddle jFiddle

The desired order: 所需的顺序:

  1. Click 点击
  2. Width increases in 0.5 s 宽度增加0.5秒
  3. Simultaneously wait 0.5 s 同时等待0.5秒
  4. Height increases in 0.5 s 高度增加0.5秒

Right now, it all happens at the same time in the jFiddle. 现在,这一切都发生在jFiddle的同一时间。 On my local machine it ignores the height transition (it just shoots to 300px instead of easing, and then eases the width transition). 在我的本地机器上它忽略了高度转换(它只是300px而不是缓和,然后缓和宽度转换)。

Any ideas? 有任何想法吗?

If I understand you correctly, 如果我理解正确,

The first duration value is affect on the first duration etc. So you need to change the transition-duration to 1s, 0.5s instead of 0.5s, 0.5s . 第一个持续时间值会影响第一个持续时间等。因此,您需要将transition-duration更改为1s, 0.5s而不是0.5s, 0.5s

Like this: 像这样:

 $(document).ready(function() { $("#resize").click(function() { $("#resize").toggleClass("active"); }); }); 
 #resize.active { width: 100%; height: 300px; -webkit-transition-property: height, width; -webkit-transition-duration: 1s, 0.5s; -webkit-transition-delay: 1s, 0.5s; transition-property: height, width; transition-duration: 1s, 0.5s; transition-delay: 1s, 0.5s; } #resize { background-color: blue; height: 45px; width: 100px; -webkit-transition-property: width, height; -webkit-transition-duration: 0.5s, 1s; -webkit-transition-delay: 0.5s, 1s; transition-property: width, height; transition-duration: 0.5s, 1s; transition-delay: 0, 1s; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="resize"> <h1> Stuff </h1> </div> 

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

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