I am making a simple mobile webpage where I have an image with an image map over it. I want the image to change when the user touches the image, and change back when the user lifts their finger. The image is broken into 3 parts, and the image it switches to on touch varies based on which of the 3 areas they touched.
My problem is I cant get the touchstart event to fire for an image map area, on IOS or Android. If I use onmousedown it works properly, but IOS dosnt seem to fire this event until the user has already lifted their finger, which dosnt work for me. I can get ontouchstart to work if I listen for it on a div or image, so I know my event handlers etc are correct.
Does anyone know how I can get my image map to fire the touch events properly, or another html element that can accomplish the same thing?
<html>
<head><title>Touch Test</title></head>
<body>
<script type="text/javascript">
//the handler I want to fire
function onTouchStart(e){
alert('touch me more');
}
</script>
<div style="height:250px">
<div id="log"></div>
<div id="logDetails"></div>
<!--If I dont have the image map over the image, this ontouchstart fires properly-->
<img src='img/nbsLogo.png' ontouchstart="onTouchStart(event)" usemap='#imageMap'/>
<!--The touch event fires on this div properly as well-->
<!--<div id="box" style="height:225px;width:225px;background:red;position:absolute;" ontouchmove="touchMove(event)" ontouchstart="onTouchStart(event)"></div> -->
</div>
<map id='imageMap' name='imageMap'>
<!-- This touch event never fires. If I make it onmousedown, it fires properly, but only after the user has lifted their finger-->
<area id='coldDark' title='coldDark' shape='rect' ontouchstart='onTouchStart(event)' coords='0,0,361,272'>
</map>
</body>
</html>
Any help is greatly appreciated
Thank you