源码下载:链接:
https://pan.baidu.com/s/1F-3_zqIQ5V4_MzWv6EVikQ 密码:riq3
<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<style type="text/css">
.dd-demo1 {
width: 160px;
height: 160px;
border: 2px solid #d3d3d3;
position: absolute;
background: url('img/bigDiv.png');
overflow: hidden;
word-break:break-all;
}
.dd-demo2 {
width: 160px;
height: 80px;
border: 2px solid #d3d3d3;
position: absolute;
background: url('img/smallDiv.png');
overflow: hidden;
word-break:break-all;
}
.proxy {
border: 1px dotted #333;
width: 160px;
height: 160px;
text-align: center;
background: #fafafa;
}
#dd1 {
background: url('img/bigDiv.png');
left: 20px;
top: 20px;
}
#dd2 {
background: url('img/smallDiv.png');
left: 20px;
top: 200px;
}
.direction{
width: 50px;
height: 50px;
position: absolute;
}
#right{
left:105px;
top:360px;
}
#left{
left:20px;
top:325px;
}
#up{
left:80px;
top:300px;
}
#down{
left:45px;
top:390px;
}
</style>
</head>
<body>
<div id="all">
<div id="dd1" title="拖动我试试" class="dd-demo1">
</div>
<div id="dd2" title="拖动我试试" class="dd-demo2">
</div>
<div id="writeSth" style="float: inherit;display: none;">
<input type="text" id="content">
</div>
<div id="right" class="direction" style="background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;">
</div>
<div id="left" class="direction" style="background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;transform:rotate(180deg);">
</div>
<div id="up" class="direction" style="background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;transform:rotate(-90deg);">
</div>
<div id="down" class="direction" style="background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;transform:rotate(90deg);">
</div>
<div id="del" title="移到这里删除" style="background: url('img/del.png'); background-size:50px 50px;position: absolute; left:20px; top:500px; width: 50px; height:50px;"></div>
</div>
</body>
<script type="text/javascript">
//删除的绝对位置
var topDiv = $("#del").offset().top; //距离上
var leftDiv = $("#del").offset().left; //距离左
//移动div
$(function(){
//大div
$('#dd1').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(5);
$("#all").append("<div id='d"+mathR+"' class='dd-demo1' style=\"background: url('img/bigDiv.png');;left:"+(event.clientX-40)+"px;top:"+(event.clientY-40)+"px;\" οndblclick=\"writeSth('"+mathR+"')\"><input type='hidden' id='"+mathR+"'><span></span><div>");
$("#d"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
//小div
$('#dd2').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(5);
$("#all").append("<div id='d"+mathR+"' class='dd-demo2' style=\"background: url('img/smallDiv.png');;left:"+(event.clientX-40)+"px;top:"+(event.clientY-40)+"px;\" οndblclick=\"writeSth('"+mathR+"')\"><input type='hidden' id='"+mathR+"'><span></span><div>");
$("#d"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
});
//移动箭头
//右
$(function(){
$('#right').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(4);
$("#all").append("<div id='r"+mathR+"' class='direction' style=\"background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;left:"+(event.clientX-30)+"px;top:"+(event.clientY-6)+"px;\"><div>");
$("#r"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
});
//左
$(function(){
$('#left').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(4);
$("#all").append("<div id='r"+mathR+"' class='direction' style=\"background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;left:"+(event.clientX-30)+"px;top:"+(event.clientY-6)+"px; transform:rotate(180deg);\"><div>");
$("#r"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
});
//上
$(function(){
$('#up').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(4);
$("#all").append("<div id='r"+mathR+"' class='direction' style=\"background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;left:"+(event.clientX-30)+"px;top:"+(event.clientY-6)+"px; transform:rotate(-90deg);\"><div>");
$("#r"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
});
//下
$(function(){
$('#down').draggable({
proxy:'clone',
revert:true,
onStopDrag : function (event){
var mathR = generateMixed(4);
$("#all").append("<div id='r"+mathR+"' class='direction' style=\"background: url('img/right.png'); background-repeat: no-repeat;background-size: 50px 16px;left:"+(event.clientX-30)+"px;top:"+(event.clientY-6)+"px; transform:rotate(90deg);\"><div>");
$("#r"+mathR).draggable({
onStopDrag : function (event){
if(event.clientX > leftDiv && event.clientX < (leftDiv+50) && event.clientY > topDiv && event.clientY < (topDiv+50)){
var msg = "您真的确定要删除吗?\n请确认!";
if (!confirm(msg)){
return;
}else{
$("#"+this.id).remove();
}
}
}
});
}
});
});
function writeSth(ids){
if($("#writeSth").is(":hidden")){
$("#content").val($("#d"+ids+" span").text());
$("#writeSth").show();
$("#writeSth").attr("style","left:"+($('#d'+ids).offset().left+165)+"px; top:"+$('#d'+ids).offset().top+"px; position: absolute;");
$("#content").attr("onkeyup","contentToDiv('"+ids+"')");
//$("#content").val();
}else{
$("#writeSth").hide();
}
}
//将input框的内容写到div上
function contentToDiv(ids){
$("#d"+ids+" span").html($("#content").val());
$("#"+ids).val($("#content").val());
}
//获取随机数
var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
function generateMixed(n) {
var res = "";
for(var i = 0; i < n ; i ++) {
var id = Math.ceil(Math.random()*35);
res += chars[id];
}
return res;
}
</script>
</html>