function tap (el, callback) {
let $el = document.querySelector(el)
if ($el) {
let timer
let isTap
$el.addEventListener('touchstart', () => {
isTap = true
timer = setTimeout(() => {
isTap = false
}, 100)
})
$el.addEventListener('touchend', () => {
clearTimeout(timer)
if (isTap) {
callback()
}
})
}
}
tap('.box', () => {
console.log('is tap')
})
<div class="box">123</div>
.box {
width: 200px;
height: 200px;
background: red;
}