且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CSS背景图片* .svg动画不工作

更新时间:2022-10-19 14:18:00

您可以使用svg:use重复类似的对象,例如:

 < svg> 
< defs>
< g id =shape>
< rect x =50y =50width =50height =50/>
< circle cx =50cy =50r =50/>
< / g>
< / defs>
< / svg>

此代码将呈现相同的对象:

 < svg> 
< use xlink:href =#shapex =200y =50/>
< / svg>


I have animated svg file and i want to use it as background image for div

div { background-image: url('anim.svg'); }

Image displays but animations doesn't work.

P.S. I can't use svg-object in html because i have a lot of similar objects and code of svg-object is not to short.

UPD: svg-file code:

    <?xml version="1.0" encoding="utf-8"?>
<svg height="69" width="62" class="hexagon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <polygon points="30 0, 60 16, 60 50, 30 68, 0 50, 0 16" style="fill: none; stroke:#fff;stroke-width:1" />
    <polygon points="33 3, 33 3" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="33 3, 59 48" fill="freeze" />
    </polygon>
    <polygon points="28 2, 28 2" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="28 2, 0 49" fill="freeze" />
    </polygon>
    <polygon points="3 51, 3 51" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="3 51, 57 51" fill="freeze" />
    </polygon>
</svg> 

You can use svg:use to repeat the similar objects, e.g:

<svg>
  <defs>
    <g id="shape">
        <rect x="50" y="50" width="50" height="50" />
        <circle cx="50" cy="50" r="50" />
    </g>
  </defs>
</svg>

This code will render the same object:

<svg>
  <use xlink:href="#shape" x="200" y="50" />
</svg>