jquery - How to get mouseposition (pageX , pageY) during mousemove with pressed mousebutton -


i need actual mouseposition of every move when mousebutton pressed.

i used following:

var time, click= $( '#foo li' );     click.mousedown(function(e){                 time= setinterval(function(){                     $( '#foo li' ).mousemove(function( event ) {                         var msg = "handler .mousemove() called @ ";                         msg += event.pagex + ", " + event.pagey;                         $( ".output" ).empty();                         $( ".output' ).append( msg );                     });             }, 500);             return false;         });          $(document).mouseup(function(e){             clearinterval(time);             $(window).unbind( 'mousemove');             return false;         }); 

it works fine: every position printed in 'output'. mouseup event not stop mousemove function. problem?

update:

sorry,im beginner...

i tried way , works fine. there better way tell me...

var down = false; $('#foo').mousedown(function(){     down = true; });  $(document).mouseup(function(){     down = false; })  $('#foo').mousemove(function(e){     if(down == false) return;       $('.output').empty();       $('.output').append(e.pagex +' & ' + e.pagey); }); 

try this:

var click= $( '#foo li' );  click.mousedown(function(e){    $( '#foo li' ).mousemove(function( event ) {      var msg = "handler .mousemove() called @ ";      msg += event.pagex + ", " + event.pagey;      $( '.output' ).empty();      $( '.output' ).append( msg );    });  });    $(document).mouseup(function(e){    $( '#foo li' ).unbind( 'mousemove');  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="output"></div>  <div id="foo">    <li>test</li>    <li>test</li>    <li>test</li>    <li>test</li>    <li>test</li>    <li>test</li>    <li>test</li>  </div>


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -