javascript - Jquery-ui Save position of draggable item -


i want keep var of x , y position of draggable item on stop. thank fiddle , topic did :

$("#image").draggable({         helper: 'clone',     stop:function(event,ui) {         var wrapper = $("#wrapper").offset();         var borderleft = parseint($("#wrapper").css("border-left-width"),10);         var bordertop = parseint($("#wrapper").css("border-top-width"),10);         var pos = ui.helper.offset();         $("#source_x").val(pos.left - wrapper.left - borderleft);         $("#source_y").val(pos.top - wrapper.top - bordertop);         alert($("#source_x").val() + "," + $("#source_y").val());     } }); 

i want save position each time move item , use in other javascript function.

here fiddle.js :

http://jsfiddle.net/oe0fg84b/

as mentioned @john, looks you're storing x , y coordinates of draggable image in elements #source_x , #source_y, respectively.

you should able access them in function follows:

var x =$("#source_x").val();  var y = $("#source_y").val(); 

just observation, helper property clone seems causing image reset it's position after being dragged. suspect overriding coordinate values, resetting 0,0 each time. try:

$("#image").draggable({ stop:function(event,ui) {     var wrapper = $("#wrapper").offset();     var borderleft = parseint($("#wrapper").css("border-left-width"),10);     var bordertop = parseint($("#wrapper").css("border-top-width"),10);     var pos = ui.helper.offset();     $("#source_x").val(pos.left - wrapper.left - borderleft);     $("#source_y").val(pos.top - wrapper.top - bordertop);     alert($("#source_x").val() + "," + $("#source_y").val());     } }); 

i've modified example later coordinates upon button click: http://jsfiddle.net/jason_graham/oe0fg84b/2/


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -