移動端頁面彈出對話方塊效果Demo,頁面彈出對話方塊demo

來源:互聯網
上載者:User

移動端頁面彈出對話方塊效果Demo,頁面彈出對話方塊demo

核心思路:設定一個隱藏的(display:none;)、背景偏暗的div及其子div作為對話方塊,當點擊某處時,將此div設定為顯示。

核心代碼如下(部分js代碼用於動態調整div內容的行高,這部分代碼可以忽略):

<!doctype html><html>    <head>        <meta charset="utf-8">        <link rel="stylesheet" type="text/css" href="demo.css">        <script src="jquery-1.10.1.min.js"></script>        <script>            function getHeight(className) {                var height = $(className).height();                return height;            }            function setLineHeight(className) {                var height = getHeight(className) + "px";                $(className).css("line-height",height);            }            $(function() {                //調整行高並設定回呼函數,視窗一動我也動                setLineHeight(".init-page-btn");                setLineHeight(".hidden-alert");                window.onresize = function(){                    setLineHeight(".init-page-btn");                    setLineHeight(".hidden-alert");                };                //點擊"點我"按鈕就快顯視窗讓我填寫手機號碼                $(".init-page-btn").click(function(){                    $(".hidden-bg").show();                    setLineHeight(".hidden-alert");                });                //點擊快顯視窗中的"叉",快顯視窗就消失                $(".hidden-alert-close").click(function(){                    $(".hidden-bg").hide();                });            });        </script>    </head>    <body>        <div class="init-page">            <div class="init-page-btn">點我</div>        </div>        <div class="hidden-bg">            <div class="hidden-alert">                <span>請輸入手機號:<input type="text"></span>                 <div class="hidden-alert-close">叉</div>            </div>        </div>    </body></html>

初始頁面效果:

彈出對話方塊後的效果為:



查看效果和完整代碼可以下載以下檔案:

點擊開啟連結

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.