I'm making a html/js game, and attempting to add on screen controls for mobile use. However, I have found that pressing and holding on a button on mobile will highlight the button as though it is pressed but no onMouseDown event is fired and the page is simply waiting for you to swipe to scroll.

Is there an easy fix to this, to allow a mobile user to press and hold a button, or some other way to emulate the separate OnMouseDown/OnMouseUp functions?

Recommended Answers

All 4 Replies

Thank you rproffitt, I appologize for not being clear. My code functions, click and hold works, key presses work. My issue is specifically mobile does not seem to register that a button is touched if it is held.

Button mousedown/mouseup events will only fire off if the button is clicked (same with mouseclick) on mobile, any delay between mousedown and mouseup prevents both from activating as the device sets to scroll the page.

I also tried adding OnTouchStart/OnTouchEnd to the button element, but that seemed to disable all touch function to the page, preventing scrolling and using any other element that had previously worked.

You'll have to tell more. I often find this is an issue with the mobile's browser. To which I install Chrome and re-test. As to your code, I don't see it here so I can't check it out.

My appologies, it seemed to have been an issue with chrome's usb debug mode. onTouchStart/onTouchEnd seems to have solved the issue.

Thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.