2014-06-19 214 views
10

我已经使用css3为SVG创建了一个动画,它可以在Chrome和Firefox中完美运行。它是在Safari部分工作,但在Internet Explorer中无法正常工作(IE9 +支持CSS动画)CSS3动画不起作用

See Demo

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中正常工作?

+3

我不知道你的代码有什么问题,或者如果这些信息对你有帮助,但是在一小时的代码破解之后,**我能够在IE **中不显示动画的情况下显示它。 我改变了CSS块'svg *'中的'fill-opacity'。选中这个[小提琴](http://jsfiddle.net/c87vY/4/) – Rohith

+0

这似乎是一个理想的后备,因为动画是结冰,你真的只需要看看蛋糕。 – misterManSam

+0

+1,因为动画很酷:) –

回答

0

IE9不支持CSS3动画,这就解释了它在IE9中无法使用的原因。这同样适用于Safari,它也可能有助于给每个浏览器的版本。请参考以下支持的功能列表:http://caniuse.com/css-animation

+0

Morgan,Ok我同意它不支持IE9,但它应该适用于IE10 +和safari –

+0

虽然有哪些版本?你不是在说什么版本的Safari。我看到它在5.1.7版本中部分工作。我昨天在本地重新创建了你的动画,并且可以发誓它在IE10中工作。刚刚检查和德哦! –

+0

Safari版本5.1.7 –

4

尽管IE9支持CSS3动画,但在IE11中甚至不支持SVG动画,并且很难判断它们是否会一直存在。您可能不得不依赖动画HTML元素或使用JavaScript,它不会从用于呈现CSS动画的硬件加速中受益,但仍可能是一种可行的解决方案。

另一个想法是预渲染并将其作为gif部署,无论是每次或只在IE中。

来源:http://caniuse.com/#feat=svg-smil

+2

虽然OP不使用SMIL动画,但使用css3动画:http://caniuse.com/#feat=css-animation – commonpike