3

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

如何使用 HTML5 做到这一点?

4

1 回答 1

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>
于 2012-10-22T16:32:02.350 回答