简体   繁体   English

当我使用zoomIn动画时元素消失了

[英]Element is disappearing when i use zoomIn animation

The element is disappearing after css zoomIn animation is finished. CSS zoomIn动画完成后,该元素消失。 When i remove opacity:0 it will stop vanishing but instead the element appears before the animation (zoomIn) taking place. 当我删除opacity:0时,它将停止消失,但元素会在动画(zoomIn)发生之前出现。 Why is this happening? 为什么会这样呢?

See the behaviour here: https://jsfiddle.net/dhnvwmrs/ 在此处查看行为: https : //jsfiddle.net/dhnvwmrs/

 @-webkit-keyframes zoomIn { from { opacity: 0; -webkit-transform: scale3d(0.3, 0.3, 0.3); transform: scale3d(0.3, 0.3, 0.3); } 50% { opacity: 1; } } @keyframes zoomIn { from { opacity: 0; -webkit-transform: scale3d(0.3, 0.3, 0.3); transform: scale3d(0.3, 0.3, 0.3); } 50% { opacity: 1; } } .zoomIn { -webkit-animation-name: zoomIn; animation-name: zoomIn; } #box { height:400px; width:400px; background: red; -webkit-animation: zoomIn 2s ease .5s forwards; opacity:0; } 
 <div id="box"></div> 

You should use to instead of 50% : 您应该使用to代替50%

 @-webkit-keyframes zoomIn { from { opacity: 0; -webkit-transform: scale3d(0.3, 0.3, 0.3); transform: scale3d(0.3, 0.3, 0.3); } to { opacity: 1; } } @keyframes zoomIn { from { opacity: 0; -webkit-transform: scale3d(0.3, 0.3, 0.3); transform: scale3d(0.3, 0.3, 0.3); } to { opacity: 1; } } .zoomIn { -webkit-animation-name: zoomIn; animation-name: zoomIn; } #box { height:400px; width:400px; background: red; -webkit-animation: zoomIn 2s ease .5s forwards; opacity:0; } 
 <div id="box"></div> 

Describe properties for 100%, just copy properties from 50% and it will probably work. 描述100%的属性,只需复制50%的属性,它可能会起作用。

    @-webkit-keyframes zoomIn {
  from {
    opacity: 0;
    -webkit-transform: scale3d(0.3, 0.3, 0.3);
    transform: scale3d(0.3, 0.3, 0.3);
  }

  50% {
    opacity: 1;
  }

100% {
        opacity: 1;
      }
}

@keyframes zoomIn {
  from {
    opacity: 0;
    -webkit-transform: scale3d(0.3, 0.3, 0.3);
    transform: scale3d(0.3, 0.3, 0.3);
  }

  50% {
    opacity: 1;
  }

100% {
        opacity: 1;
      }
}

.zoomIn {
  -webkit-animation-name: zoomIn;
  animation-name: zoomIn;
}


#box {
   height:400px;
   width:400px;
   background: red;
   -webkit-animation: zoomIn 2s ease .5s forwards;
   opacity:0;
}

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

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