用户:Salt lovely/user.js:修订间差异

添加533字节 、​ 2020年12月16日 (星期三)
// Edit via Wikiplus
(// Edit via Wikiplus)
(// Edit via Wikiplus)
第54行: 第54行:
     */
     */
     function confirmUI(text = '', callback) {
     function confirmUI(text = '', callback) {
        // 安全锁,防止用户多次点击
        let safe = true
         // 容器
         // 容器
         let container = document.createElement('div')
         let container = document.createElement('div')
第64行: 第66行:
         yesBtn.textContent = '确定'
         yesBtn.textContent = '确定'
         yesBtn.addEventListener('click', () => {
         yesBtn.addEventListener('click', () => {
             callback(true)
             if (safe) {
            container.remove()
                safe = false
                callback(true)
                selfRemove() // 移除确认框
            }
         })
         })
         container.appendChild(yesBtn)
         container.appendChild(yesBtn)
第74行: 第79行:
         noBtn.textContent = '取消'
         noBtn.textContent = '取消'
         noBtn.addEventListener('click', () => {
         noBtn.addEventListener('click', () => {
             callback(false)
             if (safe) {
            container.remove()
                safe = false
                callback(false)
                selfRemove()
            }
         })
         })
        container.style.opacity = '0'
         container.appendChild(noBtn)
         container.appendChild(noBtn)
         // 显示UI
         // 显示UI
第83行: 第92行:
         container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
         container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
         container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
         container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
        container.style.opacity = '1'
        /**移除自己 */
        function selfRemove() {
            container.style.top = '-100%'
            container.style.opacity = '1'
            setTimeout(container.remove, 500)
        }
     }
     }
     // CSS
     // CSS
第98行: 第114行:
     background: #FDF6E6;
     background: #FDF6E6;
     user-select: none;
     user-select: none;
    transition: .4s ease-in;
}
}
.confirmUIcontainer > center{
.confirmUIcontainer > center{