<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery添加区块拖动排序特效 - 站长素材</title>
<script src="js/jquery.min.js"></script>
<script src="js/tool.js"></script>
<style>
#box{
width: 500px;
height: 500px;
border: 1px solid #000;
background-color: slategray;
overflow-x: hidden;
margin: 100px auto;
}
#box .div{
float: left;
height: 80px;
width: 100%;
line-height: 80px;
text-align: center;
border: 1px solid skyblue;
background-color: #fff;
}
#box .drag{
position: absolute;
width: 500px;
height: 80px;
border: 1px solid #00ff;
}
.zw{
float : left;
width: 100%;
height: 80px;
border: 1px dashed #f00;
}
</style>
</head>
<body>
<div id="box">
</div>
<div id="add" style="width: 90px;height: 60px;line-height: 60px;text-align: center;background-color: tomato;position: fixed;right: 80px;bottom: 50px;">
添加
</div>
<script>
// 添加div
$("#add").on("click", function(){
var len = $("#box").children().length;
var bgColor = Tool.randomColor2();
let divHtml = `<div class="div" style="background-color:${bgColor}">
${len+1}
</div>`
$(divHtml).appendTo("#box")
})
Tool.drags("box", "div", "drag", "zw")
</script>
</body>
</html>