javascript - onDrag event raised with incoherent values when mouse released -


i far being html/javascript expert , going crazy around problem. did not find on net regarding this, tried multiple things without success.

basically using drag functionality achieve something. don't need drag/drop, interested in drag.

here very simple sample illustrating issue :

https://jsfiddle.net/fhdolz70/2/

the div can dragged around , logging event.clientx value. values correct during drag, when release mouse, ondrag event raised once more incoherent clientx value (completely out of bounds, negative value). same happens clienty , other values associated event (not interested in other values clientx , clienty haven't checked).

why ondrag raised when mouse released ? drag on ... , why hold such weird values ? how can avoid receive last event on mouse release ?

thanks lot.

what you're seeing oddity jsfiddle. ondrag event fired on release, typically return zero. if took same code , placed in standalone file this:

<!doctype html> <html>   <head>     <meta charset="utf-8">     <title>dragtest</title>     <style>     .dragdiv {   width: 100%;   height: 50px;   background-color: red; }     </style>   </head>   <body>      <div draggable="true" class="dragdiv" ondrag="handledrag(event)"/>      <script>      function handledrag(evt){           console.log(evt.clientx);       }      </script>   </body> </html> 

your console log 0 instead of crazy number. catch last event, keep in mind there ondragend event fired on release. handling there.


Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -