我想将一个svg图像水平和垂直地居中,以响应我的窗口大小。因此,我决定将图像集成到一个div背景中。现在当我想要为我的svg添加stroke-dasharray和带有stroke-dashoffset的动画时,它不起作用。
是否可以动画化svg背景图像?
svg图像仅由许多线条组成。 这是我的svg文件(只有不同x和y值的更多线条):
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1920 1200" xml:space="preserve">
<g id="Layer_1">
<line class="path" stroke-linecap="round" fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" x1="960" y1="600" x2="2346.139" y2="-42.064"/>
</g>
</svg>
以下是我的 HTML 和 CSS 文件:
html, body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
background-color: red;
}
.Container {
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
background-image: url(Space.svg);
background-size: cover;
background-position: center;
}
.path {
stroke-dasharray: 20;
}
<body>
<div class="Container">
</div>
</body>