大家都知道我们之前写防抖都是用 lodash throttle 来做的,那没有其他方式,或许可以考虑用 css实现 怎么做呢?
废话不多说,直接上实现方式,大家可以参考使用哈
<style>
button {
animation: throttle 2s step-end forwards;
}
button:active { animation: none; }
@keyframes throttle {
from { pointer-events: none; }
to { pointer-events: all; }
}
</style>
<button onclick="console.log(Date.now())">按钮</button>