jquery-ui中的可拖动和可拖动就像一个可排序的

时间:2017-05-17 08:30:27

标签: html jquery-ui jquery-ui-draggable

我应该模拟一个数据中心机柜,可以在某些位置更换内部对象。我的工作在这里:http://jsfiddle.net/6zGLk/10/

我的Html:

<div class="objectContainer">
    <div class="object">
        This is a draggable object
    </div>
</div>
<div class="position">position 2</div>
<div class="position">position 3</div>   
<div class="position">position 4</div>

我的js:

    $( init );
    function init() {
        $('<div class="objectHolder"></div>').appendTo( '.position' ).droppable( {
          accept: '#objectContainer div',
          hoverClass: 'hovered',
            drop:function(event, ui){
                ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' } );
            }
        } );

        $('.objectContainer').droppable( {
             hoverClass: 'ui-state-highlight',
             drop:function(event, ui){
                ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' } );
            }            
        } );

        $(".object").draggable( {
            cursor: 'move',
            axis: "y",
            revert: 'invalid'
        });
    }

但是我无法将我的对象放在我的位置上,出于某些原因我无法使用jQuery UI进行排序。我不得不在班上打电话给我,我不能用特定的身份给他们打电话!

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我认为你在找类似的东西?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Sortable - 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>
  #sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
  #sortable li span { position: absolute; margin-left: -1.3em; }
  </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() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();
  } );
  </script>
</head>
<body>
 
<ul id="sortable">
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 5</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 6</li>
  <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 7</li>
</ul>
 
 
</body>
</html>