拖放多个div

时间:2012-10-22 16:17:18

标签: html drag-and-drop

我有两个<div>标签。一个有几个不同大小和位置的<div>标签,必须将它们拖到另一个div。但是,我需要拖回到前一个div,根据放下它的位置改变X和Y.

如何使用HTML5执行此操作?

1 个答案:

答案 0 :(得分:0)

试试这个:  

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Droppable - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <style>
    #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
    #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
    </style>
    <script>
    $(function() {
        $( "#draggable" ).draggable();
        $( "#droppable" ).droppable({
            drop: function( event, ui ) {
                $( this )
                    .addClass( "ui-state-highlight" )
                    .find( "p" )
                        .html( "Dropped!" );
            }
        });
    });
    </script>
</head>
<body>
 <div style="color:#0000FF">
  <h3>This is a heading</h3>
  <p>This is a paragraph.</p>
<div id="draggable" class="ui-widget-content">
    <p>Drag me to my target</p>
</div>
</div>

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


</body>
</html>