简体   繁体   English

jQuery可排序,但点击工作

[英]jQuery sortable but work on click

I am using the jQuery UI Sortable plugin to of course allow my users to drag and drop elements in a list, on the list change I am firing an ajax call to save the ordered list. 我正在使用jQuery UI Sortable插件,当然允许我的用户在列表中拖放元素,在列表更改我正在触发ajax调用以保存有序列表。

However one user is complaining that it is quite hard to drag and drop when the list requires a scroll. 然而,一个用户抱怨说,当列表需要滚动时,拖放很困难。 So basically what I am attempting to do is instead of the hold left click to drag and then release left click to drop. 所以基本上我试图做的不是按住左键单击拖动然后释放左键单击放下。

You will just left click on the element and it will become the active "drag" element and the user can move their mouse around the screen and it will follow, then on the second left click deactivate "drop" the element. 您将只需左键单击元素,它将成为活动的“拖动”元素,用户可以在屏幕上移动鼠标,然后在第二个左键单击停用“删除”元素。

I have looked at their documentation, but I can't seem to find anything that will help me out ( http://api.jqueryui.com/sortable/ ). 我查看了他们的文档,但我似乎无法找到任何可以帮助我的东西( http://api.jqueryui.com/sortable/ )。 Does anyone have any ideas or plugins that achieve this? 有没有人有任何想法或插件实现这一目标?

Regards 问候

This should help you with this: 'You will just left click on the element and it will become the active "drag" element and the user can move their mouse around the screen and it will follow, then on the second left click deactivate "drop" the element.' 这应该可以帮到你:'你只需要左键单击元素,它就会成为活动的“拖动”元素,用户可以在屏幕上移动它们的鼠标,然后在第二个左键单击停用“drop” “元素。”

HTML: HTML:

<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
</div>

Javascript: 使用Javascript:

$( function() {
  var dragging = false;

    $("#draggable").draggable();
  $("#draggable").mouseup(function(e){
    if(!dragging){
      dragging = true;
      e.preventDefault();
      return false;
    }
    else{
      dragging = false;
    }
  })
  } );

Codepen example: http://codepen.io/xszaboj/pen/JWbzax Codepen示例: http ://codepen.io/xszaboj/pen/JWbzax

I hope that is what you need. 我希望这就是你所需要的。

Side note. 边注。 This won't work on touch screen monitors on chrome because of different events which are fired. 这不适用于Chrome上的触摸屏显示器,因为触发了不同的事件。

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

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