我将一个svg文件加载到一个object标记中,并希望对其进行动画处理。我这里有一段简单的测试代码,但有一个问题:
在我的第二个css规则中,我的目标是#main,它恰好是svg元素旁边的g的id。我希望g标记具有动画效果,但它没有。如果我用#svgA替换#main,那么它就可以工作。有人知道如何用css3定位svg标签的内容吗?
谢谢
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
/* The animation code */
@keyframes example {
from {
left:0px;
}
to {
left:100px;
}
}
/* The element to apply the animation to */
#main {
position:relative;
animation-name: example;
animation-duration: 4s;
}
</style>
</head>
<body>
<object class="svgA" data="images/yeti/yeti-01.svg" type="image/svg+xml"></object>
</body>
</html> 发布于 2017-12-12 21:55:08
因为SVG是动态加载的,所以需要从SVG本身加载样式表。尝试将以下内容添加到您的SVG:
<?xml-stylesheet href="anim.css" type="text/css"?>其中anim.css是定义CSS3动画的样式表。
发布于 2015-06-27 08:23:27
您可以使用变换来设置svg元素的动画。
/* The animation code */
@keyframes example {
from {
transform: translateX(0px);
}
to {
transform: translateX(100px);
}
}
/* The element to apply the animation to */
#main {
position:relative;
animation-name: example;
animation-duration: 4s;
} <svg>
<g id="main">
<circle cx="50" cy="50" r="40" fill="red" />
</g>
</svg>
https://stackoverflow.com/questions/31083621
复制相似问题