javascript - How To Detect Mouse Move ONLY on Horizontal Move (To Left or to Right Move) -


can please take @ this demo , let me know how can detect mousemove() when mouse moving left or right?

basically happening jquery detecting mousemove event when mouse moving top down or down top need disable , detect mouse move event on moving horizontally.

$( "#target" ).mousemove(function( event ) {    var msg = "handler .mousemove() called @ ";    msg += event.pagex + ", " + event.pagey;    $( "#log" ).append( "<div>" + msg + "</div>" );  });
#target{width:500px; height:120px; background:yellow;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="target">    move here  </div>  <div id="other">    trigger handler  </div>  <div id="log"></div>

record last position of mouse , if horizontal position has changed, run code.

var lastx = 0;    $( "#target" ).mousemove(function( event ) {    if(lastx != event.pagex) {      var msg = "handler .mousemove() called @ ";      msg += event.pagex + ", " + event.pagey;      $( "#log" ).append( "<div>" + msg + "</div>" );    }    lastx = event.pagex;  });
#target{width:500px; height:120px; background:yellow;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="target">    move here  </div>  <div id="other">    trigger handler  </div>  <div id="log"></div>


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -