Michael Mikhjian
Michael Mikhjian

Reputation: 2794

on touchmove modify each element touched

I've been searching around for this and can't seem to find anything.

Basically I've binded a "touchmove" event (via jQuery) to a set of divs.. what I was hoping would happen is, as you drag across each div (with out touchend) the div's attr "xyz" toggles from 0 to 1 aka meaning it's been touched.

$("#itBoardFront div").on('touchmove',function(e){
    $(this).attr('data-hit',1);
})  

As you can assume, this is not working. Only the element that's actually being hit on and moved on is getting the data-hit =1.

Upvotes: 1

Views: 2426

Answers (2)

Michael Mikhjian
Michael Mikhjian

Reputation: 2794

I was able to solve this by catching the coordinates of the touch end positions then comparing it with each potential div's x,y,w,h.

Upvotes: 1

Ido Green
Ido Green

Reputation: 2813

You will need to 'touch and then move' per div. This is due to the way the events are fire on your elements. You can see this example: http://jsfiddle.net/MpJUR/6/ In each div (except the first one that took it by default) you need to click/touch first and then move in order to get the event trigger. BTW, the event will be trigger on each 'move' to it's not efficient. You might want to catch 'touchstart' per div and/or just work with 'touchmove' on a parent elem that contain all the divs.

Upvotes: 0

Related Questions