Jquery draggable persistence either through mysql or saving cookie in the database?
I want to know that how can I persist the divs dropped on a draggable. I have been trying since long but stuck at this point. Actually you can see the demo here. I have to save the user designed wedding floor. So whenever user logins next time he/ she is able to see the last design saved. The code is shown below:
$(document).ready(function() {
$("#droppable").droppable({
accept: '.draggable',
drop: function(event, ui) {
$(this).append($(ui.draggable).clone());
$("#droppable .draggable").addClass("objects");
$(".objects").removeClass("ui-draggable draggable");
$(".objects").draggable({
containment: 'parent',
});
}
});
开发者_如何学C $(".draggable").draggable({
helper: 'clone',
tolerance: 'touch',
cursor:'move'
});
});
- Get Position of each Object (easy to do with JQuery)
- Serialize to JSON and save to a database of your choice. Don't use cookies for this.
I have already asked to this kind of question read this:
jQuery UI sortable: determining in what order the items are
and this:
Getting the position of the element in a list when it's drag/dropped (ui.sortable)
hope this help
There's a nice tutorial and demo of how to drag-and-drop with PHP,jQuery-UI and MySQL here: PaperMashup
精彩评论