自定义弹出框

遇到一个需要自定义弹出框的项目,找到了一个感觉比较好的js代码。收藏一下

//限制页面是否可滚动(弹窗出现时)var doc = document.documentElement;var preventDefault = function (e) {e.preventDefault();}function stop() {doc.style.overflow = 'hidden';doc.addEventListener('touchmove',preventDefault,false);}function scroll() {doc.style.overflow = 'auto';doc.removeEventListener('touchmove',preventDefault,false);}function dialog(obj){var $body = $('body');obj.width = obj.width||'380px';//var html = ''+                '

' +                    '

提示' +            'X

'+                    '

'+obj.text+'

';if(obj.button){console.log('a')html = html +  '



取消

'        }html = html + '

';$(html).appendTo($body)        stop();}function closeDialog() {$("#commonDialog").remove();scroll();}    dialog({        text: '

确定删除?

确定删除?

',        button: true,        event: '_delete'    })    function _delete(){    closeDialog();        dialog({            text: '已删除',            button: false        })    }

你可能感兴趣的:(自定义弹出框)