jQuery UI Draggable如何获取拖动开始位置 [英] JQuery UI Draggable how to get drag start position

查看:590
本文介绍了jQuery UI Draggable如何获取拖动开始位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以拖动可拖动的物品并将其放到我的可放物品上,并从 ui.absolutePosition放置事件.我需要知道阻力从哪个位置开始. 我尝试在拖动开始事件上获取ui.position,但这是空的.我也尝试过 ui.position在拖动事件上,但这是未定义的.

I can drag my draggable items and drop them on my droppables and get the drop position from ui.absolutePosition on the drop event. I need to know what position the drag started from. I have tried getting ui.position on the drag start event but this is null. I've also tried ui.position on the drag event but this is undefined.

有什么想法吗?

推荐答案

您应该能够使用.droppable的drop函数中的ui.draggable来获取所需内容.

You should be able to use the ui.draggable from the .droppable's drop function to get what you're after.

ui.draggable.offset()

也许.

如果要在拖动开始时获得准确的鼠标位置,则可以在.draggable()启动函数上使用event.clientX和event.clientY

If you want the exact mouse position on start of drag, you can use the event.clientX and event.clientY on the .draggable() start function

$('selector').draggable({ ...options...
      start: function(event, ui) {
                   alert("You clicked x:" + event.clientX + " y:" + event.clientY);
             }
});

这篇关于jQuery UI Draggable如何获取拖动开始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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