0
好的,所以繼承了我在js上的一些代碼。當前的代碼允許我移動對象,並顯示對象相對於其約束的停止和起始位置。我需要做的是獲得每個對象返回的位置。我需要把它們儲存在不同的變量中。這個想法是,他們將能夠動態地添加新的形狀,這些形狀都會返回座標,我可以讓他們「保存」,這將使用所有這些變量和AJAX他們到數據庫。目前它只返回最新拖動的對象,我怎麼修改這個以允許它顯示每個對象的位置。我對使用JQuery/JQueryUI有點新,所以向正確的方向推動是有幫助的。顯示每個可拖動元素的位置
$(init);
function init() {
$('.square, .round').draggable({
containment: '#layout-area', start: function(event, ui) {
// Show start dragged position of image.
var Startpos = $(this).position();
$("div#start").text("START: \nX: "+ Startpos.left + "\nY: " + Startpos.top);
},
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var Stoppos = $(this).position();
$("div#stop").text("CURRENT: \nX: "+ Stoppos.left + "\nY: " + Stoppos.top);
}
});
}
$(document).ready(function() {
var params = {
// Callback fired on rotation start.
start: function(event, ui) {
},
// Callback fired during rotation.
rotate: function(event, ui) {
},
// Callback fired on rotation end.
stop: function(event, ui) {
},
};
$('#table, #table1, #table2, #table3, #table4, #table5').rotatable(params);
});
謝謝!
我一直在使用'localStorage'做過類似的事情。我不知道這是否是最好的方式,但它對我有效...... [localStorage](http://www.w3schools.com/html/html5_webstorage.asp) – Rasclatt 2014-09-25 16:22:02