<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="jquery.min.js"></script>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="jquery.min.js"></script>
<script src="
jquery-ui.js"></script>
<style>
.div1,.div2,.div3{
height: 100px;
width: 100px;
position: absolute;
}
.div1{
top:0;
left: 0;
}
.div2{
top:200px;
left: 0;
}
.div3{
top:400px;
left:0;
}
img{
width:100px;
height: 100px;
}
.div4{
right: 200px;
top:100px;
border: 1px #f37a0e dashed;
height: 304px;
width: 100px;
position: absolute;
}
.div5{
height: 100px;
border-bottom: 1px dashed #f37a0e;
}
.div6{
height: 100px;
border-bottom: 1px dashed #f37a0e;
}
.div7{
height: 100px;
}
</style>
</head>
<body>
<div class="div1">
<img src="1.jpg"/>
</div>
<div class="div2">
<img src="2.jpg"/>
</div>
<div class="div3">
<img src="3.jpg"/>
</div>
<div class="div4">
<div class="div5"></div>
<div class="div6"></div>
<div class="div7"></div>
</div>
</body>
<script>
$(document).ready(function(){
$('.div1').draggable();//拖动图片
$('.div2').draggable();//拖动图片
$('.div3').draggable();//拖动图片
$('.div5').click(function(){//点击某个位置,对应的图片放在该位置
$tar = $(this);
$tar.droppable({
drop:$('.div1').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
$('.div6').click(function(){
$tar = $(this);
$(this).droppable({
drop:$('.div2').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
$('.div7').click(function(){
$tar = $(this);
$(this).droppable({
drop:$('.div3').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
});
</script>
.div1,.div2,.div3{
height: 100px;
width: 100px;
position: absolute;
}
.div1{
top:0;
left: 0;
}
.div2{
top:200px;
left: 0;
}
.div3{
top:400px;
left:0;
}
img{
width:100px;
height: 100px;
}
.div4{
right: 200px;
top:100px;
border: 1px #f37a0e dashed;
height: 304px;
width: 100px;
position: absolute;
}
.div5{
height: 100px;
border-bottom: 1px dashed #f37a0e;
}
.div6{
height: 100px;
border-bottom: 1px dashed #f37a0e;
}
.div7{
height: 100px;
}
</style>
</head>
<body>
<div class="div1">
<img src="1.jpg"/>
</div>
<div class="div2">
<img src="2.jpg"/>
</div>
<div class="div3">
<img src="3.jpg"/>
</div>
<div class="div4">
<div class="div5"></div>
<div class="div6"></div>
<div class="div7"></div>
</div>
</body>
<script>
$(document).ready(function(){
$('.div1').draggable();//拖动图片
$('.div2').draggable();//拖动图片
$('.div3').draggable();//拖动图片
$('.div5').click(function(){//点击某个位置,对应的图片放在该位置
$tar = $(this);
$tar.droppable({
drop:$('.div1').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
$('.div6').click(function(){
$tar = $(this);
$(this).droppable({
drop:$('.div2').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
$('.div7').click(function(){
$tar = $(this);
$(this).droppable({
drop:$('.div3').animate({
'top':$tar.offset().top+'px',
'left':$tar.offset().left+'px'
})
});
})
});
</script>
</html>
本文介绍了一个使用jQuery UI实现的拖放交互示例。通过此示例,用户可以拖动三个图片元素,并将它们放置到指定的位置。文章展示了如何设置元素的样式、位置以及如何使用jQuery UI的draggable和droppable方法。

1万+

被折叠的 条评论
为什么被折叠?



