Sep 17, 2020

JS 多次点击后触发。可用来制作彩蛋

/** * 多次点击然后触发回调 */ export function multipleClicksAndThen (fn, times = 8, duration = 2000) { let timeStamps = [] return function() { let timeStamp = arguments[arguments.length - 1].timeStamp timeStamps.push(timeStamp) if (timeStamps.length === times) { if (timeStamps[times - 1] - timeStamps[0] < duration) { fn.apply(this, arguments) } timeStamps = [] } } }