[英]how to drag a div to the position of another div?
我是html和jquery的新手...我想在另一个下面创建3个div,例如div1,div2,依此类推...并且div应该是可拖动的,现在我想将div1拖动到div3的位置。现在的顺序应该是div3,div1,div2,...我该怎么做?
请帮我...
<html>
<head>
<title>My First Template </title>
<style type="text/css">
html {
background: url(Software.png) no-repeat center center fixed;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
}
</style>
<link rel="stylesheet" href="stylesheets/jquery.sidr.dark.css">
<script src="jquery.js" ></script>
<script src="jquery.sidr.min.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="SignUp.css">
<script src="jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$("#div1").draggable();
$("#div2").draggable();
$("#div3").draggable();
$("#div4").draggable();
});
</script>
</head>
<body>
<div id="div1" style="position: relative; left: 850px; top: 100px; width: 500px; height: 100px; background-color: white">div1</div>
<div id="div2" style="position: relative; left: 850px; top: 150px; width: 500px; height: 100px; background-color: blue">div2</div>
<div id="div3" style="position: relative; left: 850px; top: 200px; width: 500px; height: 100px; background-color: green">div3</div>
<div id="div4" style="position: relative; left: 850px; top: 250px; width: 500px; height: 100px; background-color: red">div4</div>
</body>
</html>
最简单的方法: http : //jqueryui.com/sortable/
这是来自jQuery示例的代码:
$(function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.