嗨,我使用如下方法目前保存在div如何保存我的div在页面加载时的位置而不拖动div?
的Javascript
$(document).ready(function(){
$(".ex").draggable({containment:'parent',cursor:'pointer',opacity:0.6,
stop : function() {
var id = $(this).attr("id");
var x = $(this).position().left;
var y = $(this).position().top;
$.ajax({
url: "changeContact.php", /* You need to enter the URL of your server side script*/
type: "POST",
/* add the other variables here or serialize the entire form.
Image data must be URI encoded */
data:{
cid:id,
x: x,
y: y
},
success: function(msg)
{
}
})
}
});
});
PHP
$qry = "SELECT * from contact Where CustomerID='$pid'";
$result = mysql_query($qry);
while ($row = mysql_fetch_array($result))
{
echo '<div class="ex" id="'.$row["ContactID"].'">';
echo '</div>';
}
如何保存时单独页面为onload每个数据的位置?有什么它会自己调用Ajax方法而不拖动?
哦,并且缺少ID的问题......我猜这些元素的HTML是在服务器上动态生成的?只需在其中设置适当的ID即可 - 无需在客户端上花费太多时间。如果这些条目来自数据库,请使用它们的唯一标识(可能带有前缀)作为html节点标识。 – defaude
我设法获取数据的所有位置是-5 – Ryan
对不起,但没有看到实际的HTML,我只能在这里进行粗略的猜测;)jQuery UI的“可拖动”通过简单地放置'position:absolute;并根据需要更改“顶部”和“左侧”。虽然你得到了-5,但是... 它可能是一个祖先元素被定位为'relative',因此作为抵消父母。 但正如我所说 - 这只是猜测和猜测在这里;) – defaude