在jquery-ui draggable方法中将光标位置设置为ui.helper的中心位置

Ama*_*ngh 5 html css jquery jquery-ui jquery-ui-draggable

我想光标是在中心的可拖动ui.helper.

我是这样做的

$(".soclass").draggable({

          cursor: "move",
          helper: 'clone',
          revert: "invalid",
          tolerance: "fit",
          start: function(event, ui){

             $(this).draggable("option", "cursorAt", {
            left: Math.floor(ui.helper.width() / 2),
            top: Math.floor(ui.helper.height() / 2)
          }); 


          }

      });
Run Code Online (Sandbox Code Playgroud)

使用这个我只在第一次掉落后才将光标放在中心. 如何将光标从第一次放下中心对齐.

的jsfiddle

Jul*_*ire 15

您可以访问draggable实例的offset.click属性,这几乎就是将光标设置为选项所做的设置选项的问题是,如您所述,它将仅在您下次触发启动事件时应用.但是使用该属性,您可以在当前事件上设置它.像这样:

start: function(event, ui){
    $(this).draggable('instance').offset.click = {
        left: Math.floor(ui.helper.width() / 2),
        top: Math.floor(ui.helper.height() / 2)
    }; 
}
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/38fay00b/