javascript - Why is the div not updated, after the .css() method is called? -


when finish dragging div, put previous location, stored in data-x, data-y. jquery not modify $(".current") in "up" method :

  • the data-x,data-y correctly stored,
  • the values stored showing correctly ox,oy,
  • but final values ones mousemove, though "up" method called after mousemove.

the code :

$(window).on('mouseup', function(){     if (dragdown){         var ox = $(".current").attr("data-x");         var oy = $(".current").attr("data-y");         console.log("oxy: "+ox+", "+oy); //<--- works fine         $(".current").css({"top":oy, "left":ox}); //<--- not work          console.log("up: "+$(".current").css("top")+", "+$(".current").css("left"));     }     dragdown = false; }); $(".draggable").on('mousemove', function(e){ //<--- .draggable     if (dragdown){         //...         console.log("move: "+$(".current").css("top")+", "+$(".current").css("left"));         $(".current").css({"top":resulty, "left":resultx}); //<---works fine        } });   <div id="containerdrag">     <div id="drag" class="draggable current">     </div> </div> 

so after mouseup, div stays is, instead of going values stored in data-x, data-y.

the output :

move: 16.6875px, 128px move: 15.6875px, 130px move: 15.6875px, 131px oxy: 81, 21.6875 up: 15.6875px, 132px 

and output in element console : values data , style should same :

enter image description here

so think have answer:

$(".current").css({"top":ox + "px" , "left":oy + "px"}); 

i sorry cant tell why, in other function variables must different?

https://jsfiddle.net/rf5up5fr/52/


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -