菜单项的 JavaScript 旋转在单击后卡住
大家好,我有一个圆形菜单(链接上方),我可以在其中想让所选项目旋转到“3点钟”,停在那里并打开内容。下一个选定的项目应该旋转到相同的位置并执行相同的操作等。使用 jquery.path 插件,我设法旋转 8 个项目一次,但是当我再次单击某个项目时,它根本不会继续旋转,而是重置动画。
我还认为,通过比较左侧值和顶部值,可以检查所选项目是否位于“3 点钟”位置。但是,如果有人有更好的解决方案,我很想听听。
我不希望有人给我一个完整完成的脚本,但我会感谢任何帮助,指出我的错误,为什么动画重置或为我指明正确的方向。即使 JavaScript 专家可以告诉我,我实现菜单的方法很垃圾,而且比我想象的要复杂得多。谢谢! :)
Hello all, I have a circle menu (above link) where I want the selected item to rotate to "3 o'clock", stop there and open the content. Next selected item is supposed to rotate to the same position and do the same etc. Using the jquery.path plugin, I managed to rotate the 8 items once but when I click again on an item, it simply doesn't continue to rotate but resets the animation.
Also I thought that by comparing left and top values, one could check if the selected item is on the "3 o'clock" position or not. However if someone has a better solution, I would love to hear about it.
I'm not expecting anyone to hand me a completely finished script but I would appreciate any help, pointing out my mistake why the animation resets or pointing me in the right direction. Even if a JavaScript guru could tell me that my approach to implement the menu is garbage and that it's way more complicated than I think. Thanks! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是这里的猜测,但我没有看到你在任何地方存储当前角度。这意味着您告诉它们每次从 0 开始并迭代原始数组。您需要在函数外部存储某种偏移量。像这样的事情可能会起作用:
我还认为你的结束角度和开始角度不正确。看起来表盘正在切换动画的数字,这意味着它可能正在向后移动物体,然后将它们动画到当前位置。这可能可以通过将 fin(上面的新变量)设置为 0 作为初始值来解决。
顺便说一句:您
然后您可以定义角度差异。作为 360/menu_items.length 然后有:
以及这个(在循环内):
Just a guess here, but I don't see you storing the current angle anywhere. This means that you're telling them to start at 0 each time and iterate through the original array. You need to have some sort of offset stored outside of the function. Something like this could work:
I also think that your end angle and start angle are off. It looks like the dial is switching numbers for the animation, which means that it is probably moving things backwards and then animating them to their current positions. This would probably be solved by setting fin (the new variable above) to 0 as an initial value.
As an asside: you
Then you could define the angle diff. as 360/menu_items.length and then have:
as well as this (inside the loop):