2015-08-14 108 views
1

我有一个简单的SVG动画。如何让SVG在手机上运行?

HTML:

<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/></svg> 

CSS:

.checkmark__circle { 
    stroke-dasharray: 166; 
    stroke-dashoffset: 166; 
    stroke-width: 2; 
    stroke-miterlimit: 10; 
    stroke: #7ac142; 
    fill: none; 
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards; 
} 

.checkmark { 
    width: 56px; 
    height: 56px; 
    border-radius: 50%; 
    display: block; 
    stroke-width: 2; 
    stroke: #fff; 
    stroke-miterlimit: 10; 
    margin: 20px auto; 
    box-shadow: inset 0px 0px 0px #7ac142; 
    animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both; 
} 

.checkmark__check { 
    transform-origin: 50% 50%; 
    stroke-dasharray: 48; 
    stroke-dashoffset: 48; 
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards; 
} 

@keyframes stroke { 
    100% { 
    stroke-dashoffset: 0; 
    } 
} 
@keyframes scale { 
    0%, 100% { 
    transform: none; 
    } 
    50% { 
    transform: scale3d(1.1, 1.1, 1); 
    } 
} 
@keyframes fill { 
    100% { 
    box-shadow: inset 0px 0px 0px 30px #7ac142; 
    } 
} 

Fiddle

这个SVG的问题是,它只能在桌面浏览器。当我在移动设备(iOS8上的最新Chrome和Safari)和原生Android Lollipop浏览器上进行测试时,未显示。

我已经尝试添加<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1//EN” “http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd”>但它仍然没有工作。

我应该怎么做才能使SVG在桌面和移动设备上都能正常工作?

+0

这并不甚至在桌面上工作,我(在Chrome或Opera) – Ian

+0

罚款工作Chrome在这里(v 44.0.2403.155) –

回答

1

对于移动浏览器上的SVG,SVG SMIL动画(又名<animate>元素)看起来比css动画更像better supported,如下所示。

<animate xlink:href="#checkmark__check" 
     attributeName="stroke-dashoffset" 
     from="48" 
     to="0" 
     dur="3s" 
     fill="freeze"> 

示例代码:https://jsfiddle.net/rvbssfmd/3/

下面是关于SMIL动画CSS技巧教程:https://css-tricks.com/guide-svg-animations-smil/

+0

好吧,但为什么复选标记动画较慢,圆形背景是黑色的(它的原始颜色是绿色的)? –

+0

Nvm,刚刚找到了改变持续时间和颜色的方法。 https://jsfiddle.net/rvbssfmd/5/ –

+0

这只是一个简化的例子:) – toruta39

相关问题