简体   繁体   English

简单的CSS转换不起作用

[英]Simple css transition doesn't work

I have some problem with repeating animation in Firefox and Chrome. 我在Firefox和Chrome中重复播放动画时遇到一些问题。 I use simple js to make it repeatable. 我使用简单的js使其可重复。

(function step() {
    setTimeout(function() {
        var coin7 = document.getElementById('coin7');
        coin7.style.display = 'block';
        coin7.style.height = "210px";
    }, 2000)

    setTimeout(function(){
        coin7.style.display = "none";
        coin7.style.height = "0";
    },6000);
    setTimeout(step, 7000)
})();

Demolink http://jsfiddle.net/pe461zrn/ Demolink http://jsfiddle.net/pe461zrn/

First iteration is ok in all browsers, but second and next doesn't apply css transition in FF39 and latest Chrome. 第一次迭代在所有浏览器中都可以,但是第二次和下一次不适用于FF39和最新版本的Chrome。 And it's still work fine at all iteration in IE11. 而且它在IE11的所有迭代中仍然可以正常工作。

How can I fix it? 我该如何解决?

尝试应用高度为0的高度,以确保在将显示设置为阻止后发生(这会阻止动画)

setTimeout(function(){coin7.style.height = "210px";}, 0);

Try this.. 尝试这个..

Just remove coin7.style.display = 'none'; 只需删除coin7.style.display = 'none'; and thats the solution 那就是解决方案

HTML HTML

<div id="coin7" style=""> 
  <img src="http://us.cdn4.123rf.com/168nwm/kristijanzontar/kristijanzontar1101/kristijanzontar110100013/8612198-.jpg" /> 
  </div>

CSS CSS

#coin7 {
      overflow: hidden; display: block; height: 0px;
        -moz-transition: all 3s ease-in-out;
        -webkit-transition: all 3s ease-in-out;
        -o-transition: all 3s ease-in-out;
        -ms-transition: all 3s ease-in-out;
        transition: all 3s ease-in-out;
        }

Javascript 使用Javascript

(function step() {
    setTimeout(function() {
        var coin7 = document.getElementById('coin7');
        coin7.style.display = 'block';
        coin7.style.height = "210px";
    }, 2000)

    setTimeout(function(){
        coin7.style.height = "0px";
    },6000);
    setTimeout(step, 7000)
})();

Check out this Fiddle 看看这个小提琴

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

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