jQuery點擊彈出層,彈出模態框,點擊模態框消失

來源:互聯網
上載者:User

標籤:自己   weight   ntb   alt   val   osi   function   key   min   

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 <!DOCTYPE html><html><head>    <title>jQuery彈出層 模態框</title>    <script src="./jquery.min.js" type="text/javascript"></script>    <style>        .btn{            height:100px;        }        .black_over{            display: none;            position: fixed;            width: 100%;            height: 100%;                        z-index:1001;            top: 0;            left: 0;            right: 0;            left: 0;            margin: auto;                    }        .white_content {            display: none;            position: fixed;            z-index:1002;            overflow: auto;        }    </style>    <script type="text/javascript">        $(function () {            //彈出隱藏層            function ShowDiv(show_div,bg_div){                document.getElementById(show_div).style.display=‘block‘;                document.getElementById(bg_div).style.display=‘block‘ ;                 var _windowHeight = $(window).height(),//擷取當前視窗高度                        _windowWidth = $(window).width(),//擷取當前視窗寬度                        _popupHeight = $("#"+show_div).height(),//擷取彈出層高度                        _popupWeight = $("#"+show_div).width();//擷取彈出層寬度                _posiTop = (_windowHeight - _popupHeight)/2;                _posiLeft = (_windowWidth - _popupWeight)/2;                $("#"+show_div).css({"left": _posiLeft + "px","top":_posiTop + "px","display":"block"});//設定position            };            //關閉彈出層            function CloseDiv(show_div,bg_div)            {                document.getElementById(show_div).style.display=‘none‘;                document.getElementById(bg_div).style.display=‘none‘;            };             $(".btn").click(function () {                var src = $(this).attr("src");                $("#showcont").attr("src",src);                ShowDiv(‘MyDiv‘,‘fade‘)            });            $("#fade").click(function () {                CloseDiv(‘MyDiv‘,‘fade‘)            });        });     </script></head><body><!--<input id="Button1" type="button" value="點擊彈出層" onclick="ShowDiv(‘MyDiv‘,‘fade‘)" />--><!--圖片請換成自己的,點擊圖片彈出--><img src="tu.png" alt="sd" class="btn" ><img src="pic.jpg" alt="sd" class="btn" ><!--彈出層時背景層DIV--><div id="fade" class="black_over"></div><!--彈出層的內容--> <div id="MyDiv" class="white_content"> <img src="tu.png" id="showcont"></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.