SOURCE

/**
 * 实现
 * 一个倒计时弹窗,当鼠标移动到弹窗内倒计时暂停,鼠标移出时倒计时继续
 */
function test () {
    let count = 10
    let timer = null
    return function (type) {
        if (type === 1 && !timer) {
            timer = setInterval(() => {
                if (count < 0) {
                    clearInterval(timer)
                    timer = null
                    return false
                }
                console.log(count);
                count--;
            }, 1000)
        } else if (type === 0 && timer) {
            clearInterval(timer)
            timer = null
        }
    }
}

const action = test()
// 开始
action(1)

// 暂停
// action(0)
console 命令行工具 X clear

                    
>
console