【发布时间】:2017-06-15 02:16:15
【问题描述】:
我想将 svg 图像水平和垂直居中以响应我的窗口。所以我决定将图像整合到一个 div 背景中。现在,当我想将 stroke-dasharray 和带有 stroke-dashoffset 的动画添加到我的 svg 时,它不起作用。
这可以为 svg 背景图像设置动画吗?
svg-image 仅由多行组成。 这是我的 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>
【问题讨论】:
-
/search?q=svg+animate+transform 或 /search?p=svg+animate+transform 你搜索了吗? :)
-
您必须将 CSS 放在 SVG 图像文件本身中,而不是放在容器 HTML 文件或单独的 CSS 文件中。
-
我没有看到任何尝试为问题中的任何内容设置动画,所以我无法真正创建一个答案来告诉你该怎么做,因为我真的不知道你想要做什么做。
-
它非常有可能为 SVG 背景设置动画。这个网站myapic.com 的动画做得很棒
标签: html css svg background-image svg-animate