【发布时间】:2014-08-08 00:45:12
【问题描述】:
我正在尝试在我的 SVG 上构建缩放选项。我想使用 CSS 过渡来更顺畅地进行缩放。由于某种原因,它不起作用。
<style>
#bbb {
-webkit-transition: transform 0.5s;
-moz-transition: transform 0.5s;
-o-transition: transform 0.5s;
transition: transform 0.5s;
}
</style>
<svg version="1.1" id="myimage" baseProfile="full" currentScale="1" width="800" height="600" xmlns="http://www.w3.org/2000/svg" style="border:1px solid black;background-color:black;" viewBox="0 0 800 600">
<g id="bbb" transform="scale(1) translate(0,0)">
<rect width="100%" height="100%" />
<circle cx="150" cy="100" r="80" fill="green" />
<text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text>
</g>
</svg>
<button onclick="setScale(4);">Test Scale</button>
<script>
function setScale(scale) {
document.getElementById('bbb').setAttribute("transform", 'scale(' + scale + ')');
}
</script>
任何想法如何在 SVG 变换属性上使用 CSS 过渡?
(* 编辑了一个错字)
【问题讨论】:
-
我可以让变焦效果很好。但并不像我预期的那样顺利使用过渡。
标签: javascript html css svg transform