问题
I use timestamps to accurately detect long press by comparing event timestamps with the requestAnimationFrame passed timestamp. By documentation both of these timestamps should be:
This value is the number of milliseconds elapsed from the beginning of the current document's lifetime till the event was created.
https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp
I've created a jsFiddle, if I click with a mouse on a desktop, it shows positive numbers. If I open on an iPhone 7+, it looks like there is about 40 minutes subtracted from the event's timeStamp value.
https://jsfiddle.net/2r0nzcmu/1/
window.addEventListener("touchstart", function (event) {
let text = document.querySelector("#text");
text.textContent = event.timeStamp;
})
Is this an actual bug? (and if you know a better way) How should I better detect long press?
来源:https://stackoverflow.com/questions/49920582/why-mobile-safari-touchevents-have-negative-timestamp