繁体   English   中英

IE上的CSS动画不起作用

[英]CSS animation on IE does not work

我有一个使用html和css的滚动文本横幅,它可以在Firefox和Chrome上运行,但是在IE 11中出错,当它到达第三项动画的结尾时,文本重新出现在中间并以错误的方式滚动。

文本应一次从底部单独出现一个项目,滚动到中间,稍等片刻,然后向左滚动,然后出现下一个项目。 在最后一项之后,动画应重复。

 @-webkit-keyframes left-one { 0% { -webkit-transform: translateX(100%); } 5%,28% { -webkit-transform: translateX(0); } 33%,100% { -webkit-transform: translateX(-100%); } } @-webkit-keyframes left-two { 0%,33% { -webkit-transform: translateX(100%); } 38%,61% { -webkit-transform: translateX(0); } 66%,100% { -webkit-transform: translateX(-100%); } } @-webkit-keyframes left-three { 0%,66% { -webkit-transform: translateX(100%); } 71%,95% { -webkit-transform: translateX(0); } 100% { -webkit-transform: translateX(-100%); } } /** Webkit Keyframes **/ @keyframes left-one { 0% { transform: translateX(100%); } 5%,28% { transform: translateX(0); } 33%,100% { transform: translateX(-100%); } } @keyframes left-two { 0%,33% { transform: translateX(100%); } 38%,61% { transform: translateX(0); } 66%,100% { transform: translateX(-100%); } } @keyframes left-three { 0%,66% { transform: translateX(100%); } 71%,95% { transform: translateX(0); } 100% { transform: translateX(-100%); } } .marquee { width: 100%; height: 30px; margin: 0 auto; margin-top: 1px; margin-bottom: 2px; overflow: hidden; position: relative; background-color: #222; -webkit-border-radius: 5px; border-radius: 5px; -webkit-transition: background-color 350ms; -moz-transition: background-color 350ms; -o-transition: background-color 350ms; -ms-transition: background-color 350ms; transition: background-color 350ms; background: -webkit-linear-gradient(left, rgba(32, 32, 32, 0), rgba(32, 32, 320, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 0)); /*Safari 5.1-6*/ background: -o-linear-gradient(right, rgba(32, 32, 32, 0), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 0)); /*Opera 11.1-12*/ background: -moz-linear-gradient(right, rgba(32, 32, 32, 0), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 0)); /*Fx 3.6-15*/ background: -ms-linear-gradient(right, rgba(32, 32, 32, 0), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 0)); /*IE*/ background: linear-gradient(to right, rgba(32, 32, 32, 0), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 1), rgba(32, 32, 32, 0)); /*Standard*/ } .marquee p { position: absolute; width: 100%; height: 100%; margin: 0; line-height: 28px; text-align: center; color: #FCCC0C; filter: dropshadow(color=#000000, offx=1, offy=1); text-shadow: 0px 0px 1px #FCCC0C; transform: translateX(100%); -webkit-transform: translateX(100%); } .marquee p:nth-child(1) { animation: left-one 15s ease infinite; -webkit-animation: left-one 15s ease infinite; } .marquee p:nth-child(2) { animation: left-two 15s ease infinite; -webkit-animation: left-two 15s ease infinite; } .marquee p:nth-child(3) { animation: left-three 15s ease infinite; -webkit-animation: left-three 15s ease infinite; } 
 <div class="marquee"> <p><a>1. Text to scroll item.</a> </p> <p><a>2 Second scroll text,</a> </p> <p><a>3 Final text item for scrolling,</a> </p> </div> 

我认为问题与您的0%关键帧有关,而IE对于从何处开始动画做一些有趣的事情。 我的意思是,当您观看自己的代码笔时,看起来文本在第二个关键帧处向右漂移,而不是在0%处。

无论如何,这里有一些代码可以解决此问题。

解决方案1:将0%更改为0.001% ,即可解决问题。

解决方案2:也许更好的方法是只编写一个动画,并在每段文本上添加一个延迟。 这是一个codepen

@-webkit-keyframes left-one {
  0% {
    -webkit-transform: translateX(100%);
  }
  20%,33% {
    -webkit-transform: translateX(0);
  }
  50%,100% {
    -webkit-transform: translateX(-100%);
  }
}

/** Webkit Keyframes **/

@keyframes left-one {
  0% {
    transform: translateX(100%);
  }
  20%,33% {
    transform: translateX(0);
  }
  50%,100% {
    transform: translateX(-100%);
  }
}

.marquee p:nth-child(1) {
  animation: left-one 15s ease  infinite;
  -webkit-animation: left-one 15s ease infinite;
}
.marquee p:nth-child(2) {
  animation: left-one 15s ease 5s infinite; // delay of 5s
  -webkit-animation: left-one 15s ease 5s infinite;
}
.marquee p:nth-child(3) {
  animation: left-one 15s ease 10s infinite; // delay of 10s
  -webkit-animation: left-one 15s ease 10s infinite;
}

暂无
暂无

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

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