HTML5 动画虚线
作为 HTML5 游戏的新手,我只是想问是否有人知道是否可以沿着路径制作虚线动画?想想诺基亚时代的蛇,只有一条虚线...
我有一条虚线(代表电流流动),我想将其动画化为“移动”以显示电流正在流向某物。
感谢罗德在这篇帖子中的回答,我已经得到了虚线,但我没有确定从哪里开始让它移动。有人知道从哪里开始吗?
谢谢!
Being relatively new to the HTML5 game, just wanted to ask if anyone knew if it was possible to animate a dashed line along a path? Think snake from Nokia days, just with a dashed line...
I've got a dashed line (which represents electrical current flow), which I'd like to animate as 'moving' to show that current is flowing to something.
Thanks to Rod's answer on this post, I've got the dashed line going, but am not sure where to start to get it moving. Anyone know where to begin?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让它在
此处工作,基于这篇文章,作者:phrogz。我做了什么:
start
参数,该参数是 0 到 99 之间的数字dashSize
,对 dash 数组的内容求和dashOffSet
为基于start
百分比的dashSize
的一小部分setInterval
将start
从 0 更新到 99,步长为 10更新
原始算法不适用于垂直或负倾斜线。添加了一项检查,以在这些情况下使用基于 y 斜率的倾斜度,而不是基于 x 斜率。
此处演示
更新的代码:
Got it working
here, based on this post by phrogz.What i did:
start
parameter which is a number between 0 and 99dashSize
summing the contents of the dash arraydashOffSet
as a fraction ofdashSize
based onstart
percentsetInterval
to update thestart
from 0 to 99, step of 10Update
The original algorithm wasn't working for vertical or negative inclined lines. Added a check to use the inclination based on the y slope on those cases, and not on the x slope.
Demo here
Updated code:
您可以使用 SNAPSVG 库创建虚线动画。
请在此处查看教程DEMO
You can create the dashed line animation using SNAPSVG library.
Please check the tutorial here DEMO