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 :
so think have answer:
$(".current").css({"top":ox + "px" , "left":oy + "px"});
i sorry cant tell why, in other function variables must different?
Comments
Post a Comment