加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

HTML实现遮罩层的方法 HTML中如何使用遮罩层

发布时间:2020-03-20 18:11:51 所属栏目:编程 来源:站长网
导读:副标题#e# Web页面中使用遮罩层,可防止重复操作,提示loading;也可以模拟弹出模态窗口。 实现思路:一个DIV作为遮罩层,一个DIV显示loading动态GIF图片。在下面的示例代码中,同时展示了如何在iframe子页面中调用显示和隐藏遮罩层。 示例代码: index.htm

        'top' : (getWindowInnerHeight() - dialog.height()) / 2 + 'px',   

        'left' : (getWindowInnerWidth() - dialog.width()) / 2 + 'px'  

    });   

       

    // 窗口DIV圆角   

    dialog.find('.modal-container').css('border-radius','6px');   

       

    // 模态窗口关闭按钮事件   

    dialog.find('.btn-close').click(function(){   

        closeModal();   

    });   

       

    // 显示遮罩层   

    showOverlay();   

       

    // 显示遮罩层   

    dialog.show();   

}   

  

/**  

 * 模拟关闭模态窗口DIV  

 */  

function closeModal() {   

    $('.overlay').hide();   

    $('#modalDiv').hide();   

    $('#modalDiv').html('');   

}   

body.html

XML/HTML Code复制内容到剪贴板

<!DOCTYPE html>  

<html lang="zh-CN">  

<head>  

<meta charset="utf-8">  

<meta http-equiv="X-UA-Commpatible" content="IE=edge">  

<title>body 页面</title>  

<style type="text/css">  

* {   

    margin: 0;   

    padding: 0;   

}   

  

html, body {   

    width: 100%;   

    height: 100%;   

}   

  

.outer {   

    width: 200px;   

    height: 120px;   

    position: relative;   

    top: 50%;   

    left: 50%;   

}   

  

.inner {   

    width: 200px;   

    height: 120px;   

    position: relative;   

    top: -50%;   

    left: -50%;   

}   

  

.button {   

    width: 200px;   

    height: 40px;   

    position: relative;   

}   

    

.button#btnShowLoading {   

    top: 0;   

}   

  

.button#btnShowModal {   

    top: 30%;   

}   

  

</style>  

<script type="text/javascript">  

       

    function showOverlay() {   

        // 调用父窗口显示遮罩层和Loading提示   

        window.top.window.showLoading();   

  

        // 使用定时器模拟关闭Loading提示   

        setTimeout(function() {   

            window.top.window.hideLoading();   

        }, 3000);   

  

    }   

  

    function showModal() {   

        // 调用父窗口方法模拟弹出模态窗口   

        window.top.showModal($('#modalContent').html());   

    }   

       

</script>  

</head>  

<body>  

    <div class='outer'>  

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读