【发布时间】:2020-05-16 08:25:49
【问题描述】:
我正在尝试使用 Anime.js 将圆形的 SVG(使用 Object > Compound Path > Make 转换为 Illustrator 中的路径)变成正方形(以相同的方式转换),但是当时间轴运行时,圆圈形状被扭曲,好像路径没有被正确解释。
虽然方形看起来不错。
作为测试,您可以将shape的目标类从标记中的SVG中删除,以防止Anime.js运行并且圆圈将正确显示。
为什么 Anime.js 无法读取我的圈子?
const circlePath = 'M153.1,49.5c63.2,0,114.5,51.3,114.5,114.5s-51.3,114.5-114.5,114.5S38.6,227.2,38.6,164S89.9,49.5,153.1,49.5z';
const squarePath = 'M270.7,275.7H23.9V31h246.8V275.7z';
var timeline = anime.timeline({
autoplay: true,
direction: "alternate",
loop: true
});
timeline.add({
targets: ".shape",
d: {
value: [
circlePath,
squarePath
],
duration: 1500,
easing: "easeInOutQuad"
},
offset: 1500
});
svg {
margin: 1rem;
border: 2px solid #666;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.min.js"></script>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve">
<path class="shape" fill="blue" d="M153.1,49.5c63.2,0,114.5,51.3,114.5,114.5s-51.3,114.5-114.5,114.5S38.6,227.2,38.6,164S89.9,49.5,153.1,49.5z"/>
</svg>
【问题讨论】:
标签: javascript svg svg-animate anime.js