JavaScript& jQuery的;如何做抓取拖放 [英] JavaScript & jQuery; how to do snapping drag and drop

查看:95
本文介绍了JavaScript& jQuery的;如何做抓取拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



作为简单的棋盘游戏的一部分,我目前正在编码在JS(使用jQuery的效果)中,用户应该能够将拼贴从拖尾拖到网格上。



如何完成以下目标(最好使用jQuery)。



  1. 启用拖放到网格上

  2. 确保拖动并将物品扣入每个平方格的网格

  3. 如果平铺完全放置在网格之外,则返回到原始位置(dock)

  4. 如果瓦片在网格上(在此点被拍摄),返回电流x& y功能

  5. 使任何瓷砖被拖动轻微透明,并且全部颜色一次就到位或返回到码头。


对不起,问这样一个大问题,我在网上找不到任何准确的建议,这将是我实现的!



非常感谢,



编辑:答案

1& 2由可拖动 : http://jqueryui.com/demos/draggable

3被解决了droppable http://jqueryui.com/demos/droppable

4是通过上述方法解决,然后 $(this).position.left && $(this).position.top

5由一个简单的 $(this).css({opacity: 0.5})内部开始拖动,相反的完成拖动



Simples!

解决方案

有关互动的演示:



可拖动



Droppable



可调整大小



可选择



可排序



我希望这些演示可以帮助你。


I am looking for advice from all you wonderful people on the best way to do snapping drag and drop.

As part of a simple board game I am currently coding in JS (using jQuery for effects) users should be able to drag tiles from a dock onto a grid.

How does one complete the following objectives (preferably using jQuery).

  1. Enable drag and drop onto the grid
  2. Ensure during drag and drop items snap to each square of the grid
  3. If the tile is placed completely off the grid, return to original place (dock)
  4. If the tile is over the grid (at this point snapped), return current x & y to a function
  5. Make any tiles being dragged slightly transparent, and go full color once in place or returned to dock

Sorry to ask such a big question, I just can't find any accurate advice online that would be me achieve this!

Many thanks,

Edit: THE ANSWERS
1&2 are solved by "draggable": http://jqueryui.com/demos/draggable
3 is solved by "droppable" http://jqueryui.com/demos/droppable
4 is solved by the above to validate and then $(this).position.left && $(this).position.top
5 is solved by a simple $(this).css({opacity:0.5}) inside start on drag and the opposite on finish drag

Simples!

解决方案

There are demos about Interactions :

Draggable

Droppable

Resizable

Selectable

Sortable

I hope these demos can help you.

这篇关于JavaScript& jQuery的;如何做抓取拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆