使用jQuery實現遮罩效果的代碼(調試版)

來源:互聯網
上載者:User

標籤:style   blog   http   color   java   os   使用   io   檔案   

參考資料:陶國榮著《jQuery權威指南》P107之4.8綜合案例分析——刪除資料時的提示效果在項目中的應用

說明:本版本為調試版,是因為增加了很多調試過程中產生的邊框。

外部引入檔案有:jQuery庫檔案和兩張圖片。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        <title>刪除記錄時的提示效果</title>                <style type="text/css">            body{                font-size: 13px;            }                        .divShow{                                line-height: 32px;                /*該屬性會影響行框的布局。在應用到一個區塊層級元素時,它定義了該元素中基準之間的最小距離而不是最大距離。*/                height: 32px;                background-color: #eee;                width: 280px;                            }                        .divShow span{                border:1px red solid;                padding-left: 50px;            }                        .dialog{                width: 360px;                border: 5px solid #666;                position: absolute;/*設定成絕對位置,未知作用*/                display: none;/**/                z-index: 101;            }                                                                                                                                                .dialog .title{                border: 1px solid #0f0;                background-color: #fbaf15;                padding: 10px;/*撐開了div的寬度和高度*/                color: #fff;/*字型顏色為白色*/                font-weight: bolder;/*加粗*/            }                        .dialog .title img{                float: right;            }                                                                        .dialog .content{                background: #fff;                padding: 25px;/*撐開了上下左右的距離*/                height: 60px;            }                        .dialog .content img{                float: left;            }                        .dialog .content span{                float: left;                border:1px solid #FF0000;                padding-top: 10px;                padding-left: 10px;            }                                                .dialog .buttom{                background-color:#eee;                text-align: right;/*把按鈕也向右靠齊了*/                padding: 10px 10px 10px 0px;            }                                    .mask{                border:1px solid #0f0;                background-color: #f00;                display:none;                width: 100%;                height: 100%;                position: absolute;/*設定了絕對位置以後,高度佔滿了整個頁面*/                top: 0px;/*設定了絕對位置以後,top值才會有效*/                left: 0px;            }                                                        </style>        <script type="text/javascript" src="js/jquery-1.10.2.js"></script>                <script type="text/javascript">                        $(function(){                $("#button1").click(function(){                    $(".mask").show();                    showDialog();                    $(".dialog").show();                });                                                                                // 當調整瀏覽器視窗的大小時,發生 resize 事件。                $(window).resize(function(){                    var flag = $(".dialog").is(":visible");                    // alert(flag);                    if(!flag){                        return;                    }                    showDialog(); //重新顯示對話方塊                });                                                                // 關閉事件(實現功能:當點擊關閉圖片的時候,遮罩層和對話方塊都消失)                $(".title img").click(function(){                    $(".dialog").hide();                    $(".mask").hide();                });                                // 註冊取消按鈕點擊事件                $("#button3").click(function(){                    $(".dialog").hide();                    $(".mask").hide();                });                                // 註冊確定按鈕點擊事件                $("#button2").click(function(){                    $(".dialog").hide();                    $(".mask").hide();                                                            var length = $("input:checked").length;                    if(length!=0){                        $(".divShow").remove();                    }                                                        });                                            });                                    function showDialog(){                var objW = $(window); // 當前視窗                var objC = $(".dialog"); // 對話方塊                var brsW = objW.width(); // 目前使用者的瀏覽器視窗的寬度                var brsH = objW.height(); // 目前使用者的瀏覽器視窗的高度                //alert(brsW + "," + brsH);                var sclL = objW.scrollLeft();//返回第一個匹配元素的水平捲軸位置。這裡要查文檔。                var sclT = objW.scrollTop();                var curW = objC.width();                var curH = objC.height();                // alert(sclL + "," + sclT);                // alert(curW + "," + curH);                                                // 設定左邊距和上邊距使得對話方塊置中(最關鍵的地方)                var left = sclL + (brsW-curW)/2;                var top = sclT + (brsH-curH)/2;                objC.css(                    {                        "left":left,                        "top":top                    }                );                            }        </script>                        <meta name="author" content="Administrator" />        <!-- Date: 2014-08-24 -->    </head>    <body>        <div class="divShow">            <input type="checkbox" id="checkbox1"/>            <a href="#">這是一條可以刪除的記錄</a>            <span>                <input type="button" id="button1" value="刪除" class="btn" />            </span>        </div>                <div class="mask">            這是隱藏的遮罩層        </div>                                <div class="dialog">            <!--                對話方塊裡面有三層div,標題層,內容層,按鈕層                                -->            <div class="title" style="border: 1px solid #f00">                <img src="images/close.gif" alt="點擊可以關閉" />刪除時候提示            </div>            <div class="content" style="border: 1px solid #0f0">                <img src="images/delete.jpg"  /><span>您真的要刪除該記錄嗎?</span>            </div>            <div class="buttom" style="border: 1px solid #00f">                <input type="button" id="button2" value="確定" />&nbsp;&nbsp;                <input type="button" id="button3" value="取消" />            </div>        </div>            </body></html>

 

使用jQuery實現遮罩效果的代碼(調試版)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.