在项目开发中,经常会有防重复点击的优化操作,我们可能会使用以下几种方式来实现:
active 鼠标点击的时候,清空动画2s 以后才能触发 onclick 事件)- <style>
- .btn {
- pointer-events: all;
- animation: btnAnim 2s step-end forwards;
- }
- .btn:active {
- animation: none
- }
- @keyframes btnAnim {
- from {
- pointer-events: none;
- }
- to {
- pointer-events: all;
- }
- }
- style>
- <body>
- <button class="btn" onclick="btnClick()"> 按钮 button>
- body>
- <script>
- function btnClick(){ console.log(123) }
- script>
属性值 :all / none
all : 可以触发该元素绑定的监听事件 ;none : 无法触发绑定的监听事件 ;CSS 「选择器」 的优势,批量 设置「节流」;animation)时间;