模态框

作者: As大大 | 来源:发表于2017-07-27 09:51 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            #mask {position: fixed;bottom: 0;top: 0;right: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, .8);display: none;z-index: 99999;}
            #mask .container {width: 80%;background-color: #fff;margin: auto;border-radius: 4px;padding: 4px;top: -100%;position: relative;transition: top .5s ease;}
            #mask .container .body-header {border-bottom: 1px solid #ccc;padding: 10px;}
            #mask .container .body-content {padding: 10px;}
            #mask .container .body-content.center {line-height: 50px;}
            #mask .container .body-footer {border-top: 1px solid #ccc;padding: 10px;}
        </style>
    </head>
    
    <body>
        <button>modal</button>
        <div id="mask">
            <div class="container">
                <div class="body-header">
                    我是头部
                </div>
                <div class="body-content">
                    我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我
                </div>
                <div class="body-footer">
                    我是尾部
                </div>
            </div>
        </div>
        <script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
        <script>
        $(function() {
            var $mask = $('#mask');
            var $mask_container = $mask.find('.container');
            $('body').on('touchstart', 'button', function(event) {
                $mask.css({ 'display': 'flex' })
                setTimeout(function() {
                    $mask_container.css('top', '0px')
                }, 1)
                event.stopPropagation();
            })
    
            $('body').on('touchstart', '#mask .container', function(event) {
                $mask_container.css('top', '-100%')
                event.stopPropagation();
            },false)
    
            $(document).on('touchstart', function() {
                $mask.css('display', 'none')
                $mask_container.css('top', '-100%')
            })
        })
        </script>
    </body>
    
    </html>
    
    

    相关文章

      网友评论

          本文标题:模态框

          本文链接:https://www.haomeiwen.com/subject/xyaakxtx.html