Skip to content
Advertisement

OGX.JS How to have multiple mouse/touch events?

I’m trying to get the distance after a touch/mouse move over 2 separate elements in OGX.JS. I use the built in touch dist, which works

 this.touch.dist.set({
      target: '.box1',
      cb_move: function(obj){ ... }
 });

But how to I add another one? If I add another instance like that, it just overwrites the first one.

this.touch.dist.set({
      target: '.box2',
      cb_move: function(obj){ ... }
 });

Thanks

Advertisement

Answer

You have to create another instance of touch.dist, which is an instance of OGX.Touches.Move.

 //default instance
 this.touch.dist.set({
     target: '.box1',
     cb_move: function(obj){ ... }
 });
 this.touch.dist.enable();

 //create new instance
 this.touch.dist2 = new OGX.Touches.Move(this);
 this.touch.dist2.set({
     target: '.box2',
     cb_move: function(obj){ ... }
 });
 this.touch.dist2.enable();

Then you have to disable the instances when leaving the view, inside the view, do

 this.disable = function(){
     this.touch.dist.disable();
     this.touch.dist2.disable();
 };

 
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement