简体   繁体   English

JQuery UI Draggable - 如何知道一个元素是可拖动的初始化?

[英]JQuery UI Draggable - How to know an element is draggable initialized?

My logic is 我的逻辑是

if( !this.draginited() ) // a drag-disabled element shouldn't get pass here, as it is inited
  this.draggable({...})

I searched a lot and couldn't find a way to implement this logic, any ideas? 我搜索了很多,找不到实现这个逻辑的方法,任何想法?

Maybe there's an easier way, but the docs say: 也许有一种更简单的方法,但文档说:

Draggable elements gets a class of ui-draggable 可拖动元素获得一个ui-draggable类

so you could do something like: 所以你可以这样做:

if(!$("#foo").hasClass("ui-draggable")) {
    ...
}

so to wrap that up (untested): 所以包装它(未经测试):

$.fn.isDraggable = function() {
    return $(this).hasClass("ui-draggable");
}

console.log($("#someElement").isDraggable());

The dragstart event is fired when dragging is started. 启动拖动时会触发dragstart事件。 More in the docs 更多的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM