JavaScript 中堆叠行为的逻辑
我正在尝试编写一些 javascript,通过设置 z-index 来堆叠对象。
测试用例: http://christophermeyers.name/stacker/
我已经将其破解在一起,但我想将这种行为推断为更符合逻辑的行为。即:
给定 x 个元素,当元素 C 移动到顶部时,该元素上方的所有元素都必须向下移动 1,而该元素下方的所有元素应保持原位。
I'm trying to write some javascript that will stack objects by setting z-index.
Test Case:
http://christophermeyers.name/stacker/
I've hacked that together, but I'd like to extrapolate that behavior to something a little more logical. That is:
Given x number of elements, when element C is moved to the top, all elements above that element must move down 1, while all elements below that element should remain in place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你做这种事情时,“链表”可以形成一个很好的数据结构。通过一系列简单的节点跟踪可堆叠元素的顺序......
并在添加或选择新节点时更新顺序。
我在以下 URL 发布了一个用于深度排序的列表的工作示例:
我不知道没时间拉更合适的教程=/
A "linked list" makes for a good data structure when you're doing this kind of thing. Keep track of the order of your stackable elements via a series of simple nodes..
..and update the sequence as new nodes are added or selected.
I have posted a working example of a list being used for depth sorting at the following URL:
Sorry I don't have time to pull up a more appropriate tutorial =/