简体   繁体   中英

Clicking a Button on iPad or Android slow using Javascript

If I click faster than approx 500ms, clicks get lost. I'm clicking ABABAB... I've tried onclick as well, same problem.

body = document.getElementById "body"
d = null
command = ''
start = new Date()

f = (title) =>
    res = document.createElement 'button'
    res.innerHTML = title
    res.style = "width:300px;height:300px"
    body.appendChild res
    res.ontouchstart = =>
        t = new Date()
        command += title + "#{t-start} "
        d.innerHTML = command
        start = t

f 'A'
f 'B'
d = document.createElement 'div'
d.innerHTML = '104'
body.appendChild d

I found an answer.

ontouchend

Now down to about 150ms. So, I will use onclick on Windows/Mac and ontouchend for touch screens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM