【发布时间】:2014-08-09 18:09:04
【问题描述】:
我使用 css3 为 SVG 创建了一个动画,该动画在 Chrome 和 Firefox 中运行良好。它在 Safari 中部分工作,但在 Internet Explorer(支持 css 动画的 IE9+)中不工作
CSS:
@-webkit-keyframes dash {
70%,80% {
stroke-dashoffset: 0;
fill-opacity: 0;
}
85% {
fill-opacity: 0;
stroke-opacity: 1;
}
95% {
stroke: #17739D;
stroke-dashoffset: -301;
stroke-opacity: 0;
}
100% {
fill-opacity: 1;
stroke-dashoffset: -301;
}
}
@-ms-keyframes dash {
70%,80% {
stroke-dashoffset: 0;
fill-opacity: 0;
}
85% {
fill-opacity: 0;
stroke-opacity: 1;
}
95% {
stroke: #17739D;
stroke-dashoffset: -301;
stroke-opacity: 0;
}
100% {
fill-opacity: 1;
stroke-dashoffset: -301;
}
}
@-moz-keyframes dash {
70%,80% {
stroke-dashoffset: 0;
fill-opacity: 0;
}
85% {
fill-opacity: 0;
stroke-opacity: 1;
}
95% {
stroke: #17739D;
stroke-dashoffset: -301;
stroke-opacity: 0;
}
100% {
fill-opacity: 1;
stroke-dashoffset: -301;
}
}
@keyframes dash {
70%,80% {
stroke-dashoffset: 0;
fill-opacity: 0;
}
85% {
fill-opacity: 0;
stroke-opacity: 1;
}
95% {
stroke: #17739D;
stroke-dashoffset: -301;
stroke-opacity: 0;
}
100% {
fill-opacity: 1;
stroke-dashoffset: -301;
}
}
#Layer_1 {
margin-left: auto;
margin-right : auto;
top: 50%;
position: absolute;
left: 50%;
margin-left: -65px;
margin-top: -35px;
}
svg {
background: #fff;
display: block;
}
svg * {
stroke: #666;
#stroke: #17739D;
stroke-width: 1;
fill-opacity: 0;
stroke-dasharray: 350;
stroke-dashoffset: 440;
}
svg #bp_svg * {
-webkit-animation-name : dash;
-moz-animation-name : dash;
-ms-animation-name : dash;
animation-name : dash;
-webkit-animation-duration: 4s;
-moz-animation-duration: 4s;
-ms-animation-duration: 4s;
animation-duration: 4s;
-webkit-animation-timing-function : linear;
-moz-animation-timing-function : linear;
-ms-animation-timing-function : linear;
animation-timing-function : linear;
-webkit-animation-fill-mode : forwards;
-moz-animation-fill-mode : forwards;
-ms-animation-fill-mode : forwards;
animation-fill-mode : forwards;
}
谁能帮我弄清楚如何让它在 Safari 和 IE 中也能正常工作?
【问题讨论】:
-
我不知道你的代码有什么问题或者这些信息是否对你有帮助,但是在破解你的代码一个小时后,我可以在 IE 中显示它而不显示动画。我更改了 CSS 块
svg *中的fill-opacity。检查这个fiddle -
这似乎是一个理想的后备方案,因为动画是锦上添花,你真的只需要看看蛋糕。
-
+1 因为动画很酷:)
-
"动画 SVG 最简单的方法是使用 CSS 动画或过渡。缺点是它在 IE 中不起作用,如果你想要 IE 支持,你需要使用 requestAnimationFrame 并更新值帧按框架和脚本。”参考:jakearchibald.com/2013/animated-line-drawing-svg
-
@ChrisHardie 发布答案
标签: css svg cross-browser css-animations