Поместите перетаскиваемый объект между двумя сбрасываемыми целями - PullRequest
0 голосов
/ 22 ноября 2018

Я пытаюсь создать перетаскивание, позволяющее перетаскивать перетаскиваемый объект между двумя сбрасываемыми целями.Обе сбрасываемые цели должны одновременно получать и принимать перетаскиваемый объект и обновлять свои «Отброшенные!»статус.

Я сделал это работает, но это немного глючит.Вы должны переместить и переместить объект между двумя объектами сброса несколько раз, прежде чем они покажут сброшенный статус.

Вот результат, который я хочу:

enter image description here

Моя попытка:

https://jsfiddle.net/9Lynb2s6/

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Droppable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 100px; height: 100px;}
  #droppable { width: 150px; height: 150px; float: left; margin: 10px; }
  #droppablea { width: 150px; height: 150px; float: left; margin: 10px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
        $( "#droppablea" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
    $( "#droppable" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Object</p>
</div>


<div id="droppable" class="ui-widget-header">
  <p>Drop here</p>
</div>

<div id="droppablea" class="ui-widget-header">
  <p>Drop here</p>
</div>


</body>
</html>

1 Ответ

0 голосов
/ 22 ноября 2018

Вы можете изменить допуски для сбрасываемых предметов

http://api.jqueryui.com/droppable/#option-tolerance

$( "#droppablea" ).droppable({
  tolerance: "touch",
  drop: function( event, ui ) {
    $( this )
      .addClass( "ui-state-highlight" )
      .find( "p" )
        .html( "Dropped!" );
  }
});
$( "#droppable" ).droppable({
  tolerance: "touch",
  drop: function( event, ui ) {
    $( this )
      .addClass( "ui-state-highlight" )
      .find( "p" )
        .html( "Dropped!" );
  }
});
...