jQuery sortable / disableselection problem

2020-07-22 09:58发布

问题:

I'm having an issue with my jQuery sortable list, where the text is being selected. I discovered the function disableSelection() but can't seem to get it working.

Here's the js:

$('ul#current_projects').sortable({
placeholder: "drop-zone",
axis: 'y',
handle: 'span.handle',
opacity: 0.5,
revert: true  
});

$('ul#current_projects').disableSelection();

Here's the HTML:

<ul id="current_projects" class="ui-sortable" unselectable="on">
  <li class="project_42">
    <div class="command">
      <span class="handle"></span>
      <a href="#" class="delete"></a>
    </div>
    <a href="#" class="project">Testing</a>
  </li>
  <li class="project_52">
    <div class="command">
      <span class="handle"></span>
      <a href="#" class="delete"></a>
    </div>
    <a href="#" class="project">Testing</a>
  </li>
</ul>

It appears that the unselectable state is on, but just doen't prevent the text selection.

Any help would be appreciated

回答1:

I had similar issue and it worked for me when I used the containment: 'parent' option.

Give this a try:

$('ul#current_projects').sortable({
 placeholder: "drop-zone",
 axis: 'y',
 handle: 'span.handle',
 opacity: 0.5,
 revert: true,
 containment: 'parent'
}).disableSelection();