【问题标题】:Image transition with keyframes带有关键帧的图像过渡
【发布时间】:2013-03-17 23:50:30
【问题描述】:

嘿,伙计们,我目前正在使用 css3 关键帧构建一个图像显示(小),它正在运行,但仅在 Firefox 上以某种方式运行,我似乎无法解决这个问题 :( 它应该在最新版本的chrome firefox 和 safari,但目前只能在 firefox 中使用。

谁能帮忙?

这是应该在以上所有浏览器中工作的 css。

@keyframes cf4FadeInOut {
 0% {
   opacity:1;
 }
 17% {
   opacity:1;
 }
 25% {
   opacity:0;
 }
 92% {
   opacity:0;
 }
 100% {
   opacity:1;
 }
}

.case-image {
  position:relative;
  height:auto;
  width:32%;
}
.case-image img {
  position:absolute;
  width:                100%;
  height:               auto;
  left:0;
 border:                            3px solid #f8d206;
    -moz-border-radius:                 15px;
    border-radius:                      15px;
    margin-left:                        -3px;
    margin-right:                       -3px;

}

.case-image img {
  -webkit-animation-name: cf4FadeInOut;
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-duration: 8s;

  -moz-animation-name: cf4FadeInOut;
  -moz-animation-timing-function: ease-in-out;
  -moz-animation-iteration-count: infinite;
  -moz-animation-duration: 8s;

  -o-animation-name: cf4FadeInOut;
  -o-animation-timing-function: ease-in-out;
  -o-animation-iteration-count: infinite;
  -o-animation-duration: 8s;

  animation-name: cf4FadeInOut;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 8s;
}
.case-image img:nth-of-type(1) {
  -webkit-animation-delay: 6s;
  -moz-animation-delay: 6s;
  -o-animation-delay: 6s;
  animation-delay: 6s;
}
.case-image img:nth-of-type(2) {
  -webkit-animation-delay: 4s;
  -moz-animation-delay: 4s;
  -o-animation-delay: 4s;
  animation-delay: 4s;
}
.case-image img:nth-of-type(3) {
  -webkit-animation-delay: 2s;
  -moz-animation-delay: 2s;
  -o-animation-delay: 2s;
  animation-delay: 2s;
}
.case-image img:nth-of-type(4) {
  -webkit-animation-delay: 0;
  -moz-animation-delay: 0;
  -o-animation-delay: 0;
  animation-delay: 0;
}

【问题讨论】:

  • 你写出你的过渡属性有什么原因吗?
  • 您是否也在某处使用@-webkit-keyframes 前缀?
  • 不,我已经用教程构建了这个,没有太多的编码英雄,如果我理解正确的话 -o- -mox- -webkit- 用于不同的浏览器?
  • 在 css 验证器中还声明了以下内容:规则 405 .case-image img:nth-of-type(4) 0 is not a animation-delay value : 0
  • 是的 :) 所以你为动画指定和重复代码的方式相同,例如-moz-animation-name... -webkit-animation-name... 您需要为@keyframes 执行此操作。所以它确实增加了很多重复的代码,但是在当前支持它的浏览器中运行是必要的。

标签: css transition css-animations


【解决方案1】:

您需要为关键帧添加供应商前缀。示例见此处:http://jsfiddle.net/tjfogarty/Gzxkq/

@keyframes pulse {
    0% { width: 40px; height: 40px; }
    100% { width: 50px; height: 50px; }
}

@-webkit-keyframes pulse {
    0% { width: 40px; height: 40px; }
    100% { width: 50px; height: 50px; }
}

@-moz-keyframes pulse {
    0% { width: 40px; height: 40px; }
    100% { width: 50px; height: 50px; }
}

等等……

你也可以使用这样的东西:http://leaverou.github.com/prefixfree/ 来为你处理它。

【讨论】:

  • 非常感谢,一切都清楚多了!非常感谢!
  • 没问题,很高兴能帮上忙 :)
  • 无前缀的关键帧应该总是在最后。 (此外,Firefox 16+ 支持无前缀关键帧。)
猜你喜欢
  • 2017-08-20
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 1970-01-01
  • 1970-01-01
  • 2020-02-19
相关资源
最近更新 更多