JQ製作簡易彈窗效果

爲什麼要做這個,主要是任務需要,其次爲了不引用過多的插件。
1、先定義一個div,並把它脫離文檔流,這樣他就有機會漂浮在頁面上
2、在定義好的div裏寫彈窗的內容
3、調整樣式,設置定義好的div的高度,滿屏(寬度比較容易,高度就需要定義個函數來設置)
4、最後將div的display設置爲none,事件觸發時再將其展示。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <script src="../sas/js/jquery-1.9.1.min.js" type="text/javascript"></script>

</head>
<style>
    .dialog-show{
        display: none;
        position: absolute;
        width: 100%;
        padding:0;
        text-align: center;
        background:rgba(0,0,0,0.5);
        filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7F000000,endcolorstr=#7F000000);
        top:0;
        z-index: 9999;
    }
    .closeBtn{
        position: absolute;
        top: 10px;
        right: 10px;
        color: white;
        cursor: pointer;
    }
    .iframeBox{
        margin-top: 30px;
        height: 400px;
    }
</style>
<body style="margin: 0;padding: 0;">
<button onclick="showDialog()">查看</button>
<div id="dialogModal" class="dialog-show">
    <span class="closeBtn" onclick="closeDialog()">X</span>
    <iframe width="80%" class="iframeBox" src="http://baidu.com"></iframe>
    <!--<iframe width="80%" style="margin-top: 30px;height: 400px;" src="http://120.36.133.54:1688/Sub/Main/MainFrame.aspx"></iframe>-->
</div>
</body>
<script>
<!--初始化-->
    $(function () {
        setHeight();
    })
    //打開彈窗
    function showDialog() {
        $("#dialogModal").show()
    }
    //關閉彈窗
    function closeDialog() {
        $("#dialogModal").hide()
    }
    //設置樣式高度
    function setHeight() {
        var _useH =$(window).height();
        $("#dialogModal").height(_useH)
    }
</script>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章