嗨,我使用如下方法目前保存在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