【发布时间】:2015-01-17 01:20:56
【问题描述】:
这很简单...在区域中拖放。但是,当我将 margin 设置为拖动元素(.a1_73、.a2_73)时,放置区域没有发生任何事情。说真的,我不知道为什么。怎么了 ???没有边距,一切都会变得更好。
HTML
<div id="a1_73" class="empty">#A1</div>
<div id="a2_73" class="empty">#A2</div>
<div id="a3_73" class="empty">#A3</div>
<div id="a4_73" class="empty">#A4</div>
<div class="a1_73 dragme">.A1</div>
<div class="a2_73 dragme">.A2</div>
<div class="a4_73 dragme">.A3</div>
<div class="a3_73 dragme">.A4</div>
Javascript
$(".dragme").draggable({
start: function (event, ui) {
$(this).put_element();
}
});
$.fn.put_element = function () {
$this = $(this).attr('class').split(" ");
$this = $this[0];
$("#" + $this + "").droppable({
accept: "." + $this + "",
drop: function (event, ui) {
alert('OK');
}
})
}
CSS
#a1_73 {
width: 362px;
height: 295px;
margin-left: 748px;
margin-top: 314px;
position: absolute;
}
#a2_73 {
width: 318px;
height: 213px;
margin-left: 421px;
margin-top: 188px;
position: absolute;
}
#a3_73 {
width: 360px;
height: 243px;
margin-left: 23px;
margin-top: 367px;
position: absolute;
}
#a4_73 {
width: 396px;
height: 199px;
margin-left: 19px;
margin-top: 50px;
position: absolute;
}
.a1_73 {
margin: 162px 0px 0px 858px;
position: absolute;
}
.a2_73 {
margin: 97px 0px 0px 759px;
position: absolute;
}
.a4_73 {
margin: 33px 0px 0px 634px;
position: absolute;
}
.a3_73 {
margin: 231px 0px 0px 853px;
position: absolute;
}
div {
background-color: red;
}
.dragme {
width: 100px;
height: 100px;
background-color: black;
color: #fff;
}
RK
【问题讨论】:
-
请发布一个 sn-p(使用编辑器上的按钮)而不是指向 jsfiddle 的链接。
-
有什么错误吗?应该怎么办?你的问题在哪里?
-
没有错误,根本不起作用。
-
Whick $(this) 您计划在您的可拖动元素中使用.. 从逻辑上讲,可放置元素在您使其可放置之前如何知道可拖动元素? ..请尝试阅读Documentation以正确使用它..祝你好运
-
拖放操作在为拖动元素添加边距之前效果更好。当我想使用左/上边距在页面上设置拖动元素时出现问题。
标签: javascript jquery user-interface