Languages

Menu
Sites
Language
mousedown not working for touch

I am making a web app for Tizen. I want to get the x,y coordinates of where the user presses, and then where they release. My code works fine in a browser, but when I run it on Tizen the mouse down function only fires when I release the click

 

    $("#listener").mousedown(function(e) {  
    mouseDown.x = e.offsetX;
    mouseDown.y = e.offsetY;
    $( "#game" ).css("background-color","#0F0");
});

$("#listener").mouseup(function(e) {
    mouseUp.x = e.offsetX;
    mouseUp.y = e.offsetY;
    $( "#game" ).css("background-color","#F00");
}); 


To make sure it wasn't just an issue with the coordinates I added the background colour change. On a browser the background will turn green while the listener is being clicked, however on Tizen there is no change until the click is released; then it will flicker green for a second and then back to red.

Responses

5 Replies
Alex Dem

Hi,
I have checked on M0 device and have got the same.
just, fyi, please look at this
https://developer.tizen.org/documentation/articles/multi-touch-web-applications
Maybe you could use touchstart, (and possibly touchend) events .

   document.getElementById('listener').addEventListener("touchstart", function(e)
   {
          if(e.touches.length ==1)//one finger touch
           {
            console.log(e.touches[0].pageX);
            console.log(e.touches[0].pageY);
          }
   }, false);
Alexey.

AVSukhov

Hello, 

You can use "touchstart" event and get coordinates from event.originalEvent.touches[0].pageX

Michael Thyer

Yep thanks, touchstart works fine, but how can I get the position that they release their touch? 

Touch move is working, but not touchend or touchcancel. Is there something I am missing?

    document.addEventListener('touchend touchcancel', function() {
        e.preventDefault();
        var touch = e.touches[0];
        alert("Start " + startX + " - " + startY + " End " + touch.pageX + " - " + touch.pageY);
    });   

Any Ideas?

Alex Dem

Hi ,
Maybe you could try to use 'touchmove' and remember last coordinate?
Alexey.

Andrew Gudz

Its native javascript and you need to add 2 different listeners for those events. Also for 'touchend' e.touches is empty but you can get coords from e.changedTouches[0]