One button, detecting click and long press:
$('#button').on('click', function(e) {
e.preventDefault();
CLICK()
});
$('#button').on('mousedown touchstart', function() {
LongPressTimer = setTimeout(function() {
LONGPRESS()
}, 1000)
})
.on('mouseup mouseleave touchend', function(e) {
e.preventDefault();
e.stopPropagation();
clearTimeout(LongPressTimer)
});
Click works, long press works.
But a long press also invokes a click.
What needs to be changed so that a long press does not invoke a click?
2
Answers
The answer is based on the ideas from Justinas and Epascarello above.
You can add a boolean to check if the event fired. I am using dataset to avoid all the extra global variables.