简体   繁体   English

缓动函数不适用于 svg.js v3 旋转

[英]Easing Functions Not Working with svg.js v3 Rotate

Package Info包裹信息

"@svgdotjs/svg.js": "^3.0.16",
"svg.easing.js": "svgdotjs/svg.easing.js"

The Problem问题

Can someone please clarify how to correctly animate a rotation with an easing function using the svg.js v3 library?有人可以澄清如何使用 svg.js v3 库通过缓动函数正确地为旋转设置动画吗?

The documentation in https://svgjs.dev/docs/3.0/animating/ gives no examples, and I have tried many different ways to get it to work, but all attempts result in the default behavior, '>' (aka the ease-out function). https://svgjs.dev/docs/3.0/animating/ 中的文档没有给出示例,我尝试了许多不同的方法来让它工作,但所有尝试都会导致默认行为“>”(也就是-输出功能)。 The plugins documentation is also not verbose ( https://svgjs.dev/docs/3.0/plugins/ ), and provides no direction as to how utilize a plugin such as the svg.easing.js library.插件文档也不冗长( https://svgjs.dev/docs/3.0/plugins/ ),并且没有提供关于如何使用插件(例如 svg.easing.js 库)的说明。 Installing that package does not change the result, either.安装该软件包也不会改变结果。

My Attempts我的尝试

const mySvg = SVG(<svg>...</svg>)
const rotatable = mySvg.find('#rotatable');

rotatable.animate(3000, '<>').rotate(360);
rotatable.animate(3000, 'easeInOut').rotate(360);
rotatable.animate({ duration: 3000, ease: '<>').rotate(360);
rotatable.animate({ duration: 3000, ease: 'easeInOut').rotate(360);

// Defining an actual easing function for easeInOut
rotatable.animate({ duration: 3000, ease: function(pos) { return (-Math.cos(pos * Math.PI) / 2) + 0.5; }}).rotate(360);

// Providing the function as a string, since that's what `animate` seems to expect
rotatable.animate({ duration: 3000, ease: 'function(pos) { return (-Math.cos(pos * Math.PI) / 2) + 0.5; }'}).rotate(360);

None of the above work as desired.以上都没有按预期工作。 I have used these on a <g> and <path> element, and both result in the same behavior of just easing out (rather than easing in and out - or even just easing in).我在<g><path>元素上使用了它们,两者都导致相同的行为,只是缓出(而不是缓入和缓出 - 甚至只是缓入)。

Any help is much appreciated, as the use of this library has definitely been very helpful for all other aspects!非常感谢任何帮助,因为使用这个库肯定对所有其他方面都非常有帮助!

Even though the docs lag a clear example (sorry), you can find this:即使文档滞后了一个清晰的例子(对不起),你也可以找到这个:

The easing of the animation can be changed with the ease() method of the runner.动画的缓动可以通过跑步者的 ease() 方法来改变。

So you can call el.animate(...).ease('<>') , which should do the trick所以你可以调用el.animate(...).ease('<>') ,这应该可以解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM