javascript - How to get a difference between two cursor positions at the two different moment? -
for example have 1 position of cursor, put in variable, , want difference between variable , cursor position after 10 ms. have no idea do.
i want make such drag'n'drop might drag element without focusing concretely it. i'm here, it's bullshit, may understand want)).
<!doctype html> <html> <head> <title>example</title> <style> .red { width:500px; height:100px; background:red; cursor: move; position:relative; } .green { width:100px; height:100px; background:green; position:absolute; left:0; } </style> <script src="http://code.jquery.com/jquery-2.1.0.min.js" type="text/javascript"></script> <script type="text/javascript"> var draggble = false; var currentleft; var currentx; $(document).on("mousedown",".red",function(){ draggble = true; currentleft = parseint($(".green").css("left"),10); }); $(document).on("mouseup", "body", function () { draggble = false; }); $(document).on("mousemove","body",function(e){ currentx = e.pagex; if(draggble){ settimeout(function(){ currentleft = currentleft + currentx - e.pagex; $(".green").css("left",currentleft); },10); } }); </script> </head> <body> <div class="red"> <div class="green"></div> </div> </body> </html>
i'm sorry awful english, it's first time when need write.
Comments
Post a Comment