在通过单击按钮验证其放置后,如何将 jQuery Draggables 返回到其原始列表?
这是一个有点奇怪的愿望,但我正在使用 jQuery UI 制作一款匹配游戏,并且我希望允许用户从 jQuery draggables< 的一个
拖动元素。 /code> (列表 A),然后将其放入 jQuery
droppable
(列表 B)中。当用户确定他们认为列表 A 中的每个项目都位于列表 B 中的正确位置后,他们可以单击按钮来检查他们的答案。
这就是棘手的地方。单击检查答案后,正确的项目会变为绿色并锁定到位,而错误的项目则留在不正确的可放置项中。有人对如何将不正确的物品退回到列表 A 有什么好主意吗?
我可以发布代码,但我不确定它是否必要,我只需要想法和/或模拟实现。
谢谢!
**
编辑:
感谢 Ken,这就是我正在做的事情...当该项目被删除时,jQuery 会向其添加某些 css
属性; position:relative
、top
和 left
已更改,以便该项目将保持固定在其接受的放置位置。为了恢复这些,我只是做了以下操作(在将 CorrectLoc 添加到正确放置的项目后):
$('li:not(. CorrectLoc)').animate({top: 0 ,左:0});
谢谢肯!
**
This is a bit of a weird desire but I am making a matching game using jQuery UI, and I want to allow a user to drag an element from one <ul>
of jQuery draggables
(list A) and then drop it in a jQuery droppable
(list B). After the user has decided that they think every item from list A is in the correct place in list B, they can click a button to check their answers.
This is where it gets tricky. After clicking to check answers, the correct items are made green and locked in place, and the incorrect items are just left there in their incorrect droppables. Does anyone have any good ideas for how I could return the incorrect items back to list A?
I can post up the code but I'm not really sure it's necessary, I just need ideas and/or mock implementations.
Thanks!
**
EDIT:
So thanks to Ken this is what I'm doing... When the item is dropped it jQuery adds certain css
properties to it; position:relative
, top
, and left
are changed so that the item will remain fixed in its accepted drop location. In order to revert these I just did the following (after adding correctLoc
to the correctly dropped items):
$('li:not(.correctLoc)').animate({top: 0, left: 0});
Thanks Ken!
**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您检查正确性并将某些项目设为绿色时,大概您正在向这些项目添加一个类。因此,要重置不正确的项目,可能是这样的:
When you check for correctness and make some items green, presumably you're adding a class to those items. So to reset incorrect items, maybe something like this: