Jump to content

Coding for click event on mobile


Kartika
 Share

Recommended Posts

Hi.

I am trying to make my canvas based javascript game work for mobile. I would like to know how to translate 'click' event to touch based event. tap is given as an alternative but I am unable to find the event name . documentation just gives touchstart,touchmove and touch end. Will I have to use a package like jquery mobile?

 

TIA

 

Kartika

Link to comment
Share on other sites

to simulate "tap", you need to make use of both "touchstart" and "touchend" events.

var isTouchStart = false;document.addEventListener("touchstart", function(event){     isTouchStart = true;}, false);document.addEventListener("touchend", function(event){     if(isTouchStart == true)    {        isTouchStart = false;        console.log("tap was success!");    }}, false);

something similar to above.

Link to comment
Share on other sites

Hi,

Thanks for your reply. I am using touchstart and touchend for different purpose. jquery mobile actually uses a timer. I guess that would also be required.

 

kartika

 

to simulate "tap", you need to make use of both "touchstart" and "touchend" events.

var isTouchStart = false;document.addEventListener("touchstart", function(event){     isTouchStart = true;}, false);document.addEventListener("touchend", function(event){     if(isTouchStart == true)    {        isTouchStart = false;        console.log("tap was success!");    }}, false);

something similar to above.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...