jQuery Draggable / Droppable 定位组件
我有一个可拖动/可放置的库存设置。它基本上是一个拼图,但是是一个简单的拼图,正确的碎片会卡在正确的区域。我把折断和拼图碎片都放下来了。然而,当我将片段 1 拖到位置 2 上时,它并没有显示为无效。如何区分目标区域?
HTML:
<div id="drag">
<div id="piece-drag">
<div id="piece1">
<img src="anim/hoffmann3-anklebridge/pin 1.png" />
</div>
<div id="piece2">
<img src="anim/hoffmann3-anklebridge/pin 2.png" />
</div>
</div>
<div id="place-drop" style="background:url(puzzleshape.png) no-repeat;">
<div id="piece1drop" style="width:103px; height:36px; position:absolute; z-index:50; top:346px; left:241px;"></div>
<div id="piece2drop" style="width:103px; height:36px; position:absolute; z-index:50; top:333px; left:228px;"></div>
</div>
</div>
JQuery:
$(function(){
$("#piece1").draggable({ revert: "invalid" });
$("#piece1drop").droppable({
drop: function() {
$('#piece1').hide();
$('#piece1drop').css('background-image', 'url("piece1placed.png")');
}
});
$("#piece2").draggable({ revert: "invalid" });
$("#piece2drop").droppable({
drop: function() {
$('#piece2').hide();
$('#pin2drop').css('background-image', 'url("piece2placed.png")');
}
});
});
I have a stock setup for draggable/droppable. It's basically going to be a jigsaw, but an easy one where the correct pieces snap to the correct areas. I have the snapping and the jigsaw pieces down. However, when I drag piece 1 over place 2 it doesn't show it as being invalid. How do I differentiate between targeting zones?
HTML:
<div id="drag">
<div id="piece-drag">
<div id="piece1">
<img src="anim/hoffmann3-anklebridge/pin 1.png" />
</div>
<div id="piece2">
<img src="anim/hoffmann3-anklebridge/pin 2.png" />
</div>
</div>
<div id="place-drop" style="background:url(puzzleshape.png) no-repeat;">
<div id="piece1drop" style="width:103px; height:36px; position:absolute; z-index:50; top:346px; left:241px;"></div>
<div id="piece2drop" style="width:103px; height:36px; position:absolute; z-index:50; top:333px; left:228px;"></div>
</div>
</div>
JQuery:
$(function(){
$("#piece1").draggable({ revert: "invalid" });
$("#piece1drop").droppable({
drop: function() {
$('#piece1').hide();
$('#piece1drop').css('background-image', 'url("piece1placed.png")');
}
});
$("#piece2").draggable({ revert: "invalid" });
$("#piece2drop").droppable({
drop: function() {
$('#piece2').hide();
$('#pin2drop').css('background-image', 'url("piece2placed.png")');
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
accept: "#selector"
作为 droppable 插件的选项:这是 jQuery 演示
Add
accept: "#selector"
as an option to the droppable plugin:Here's the jQuery Demo