javascript - event.target not changed during touchmove in chrome -
i have div child elements. in touch move, need target element. target element remains same in chrome
fiddle link: https://jsfiddle.net/660rdys9/1/
var parent = document.getelementbyid("parent"); var textbox = document.getelementbyid("textbox"); parent.ontouchmove = function(e){ textbox.value = e.target.id; }
div > div{ border:2px solid; }
<div id="parent" style="width:500px;height:300px;"> <div style="width:500px;height:200px;" id="first">first span</div> <div style="width:500px;height:200px;" id="second">second span</div> </div> <input type="text" id="textbox"/>
replication procedure:
1) goto fiddle in above link using chrome
2) touch 1 of black rectangle(first div) , move finger rectangle(second child div)
3) can see id displayed in text box remains same
is behavior of touch move event? not possible correct target element during touch move?
note: event.target correct during mouse move
as per answer in question how find out actual event.target of touchmove javascript event?, can use document.elementfrompoint
method workaround
example code:
var parent = document.getelementbyid("parent"); var textbox = document.getelementbyid("textbox"); parent.ontouchmove = function(e){ var target = document.elementfrompoint(e.originalevent.changedtouches[0].clientx, e.originalevent.changedtouches[0].clienty); textbox.value = target.id; }
div > div{ border:2px solid; }
<div id="parent" style="width:500px;height:300px;"> <div style="width:500px;height:200px;" id="first">first span</div> <div style="width:500px;height:200px;" id="second">second span</div> </div> <input type="text" id="textbox"/>
Comments
Post a Comment