D
D
Dauren S2015-11-25 19:30:19
JavaScript
Dauren S, 2015-11-25 19:30:19

Mouse position right left?

How to determine where the mouse is moving to the right or to the left?
Ideally, you need a script that if the mouse moves to the right, then moves 2 objects to the left by 100px, if the mouse is to the left, then two objects to the right by 100px

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-11-25
@dauren101

(function(d, prevX){
  d.onmousemove = function(e){
       var tX = e.clientX;
       
       if(tX < prevX){
          //Мышь двинулась влево
       }else{
          //Вправо
       }

      prevX = tX;
  }
})(document, 0);

S
Stalker_RED, 2015-11-25
@Stalker_RED

Subscribe to mousemove
Compare current coordinates with those in the past.
Move something there.
jsfiddle.net/43x34xwd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question