1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| const debounce3 = function () { let timer = null return function (fn, wait, scope, immediate) { timer && clearTimeout(timer) if (immediate) { !timer && fn.call(scope) timer = setTimeout(() => { timer = null count = 0 }, wait) } else { timer = setTimeout(function () { fn.call(scope) timer = null }, wait) } } }()
debounce3(function () { paras[index - 1].innerHTML += ' 立即执行的内容' }, 1000, null, true)
debounce3(function () { paras[index - 1].innerHTML += ' 延迟执行的内容' }, 1000)
|