RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
HTML中怎么使用遮罩层

这篇文章给大家分享的是有关HTML中怎么使用遮罩层的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

10年积累的成都做网站、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有宁洱免费网站建设让你可以放心的选择与我们合作。

Web页面中使用遮罩层,可防止重复操作,提示loading;也可以模拟弹出模态窗口。

实现思路:一个p作为遮罩层,一个p显示loading动态GIF图片。在下面的示例代码中,同时展示了如何在iframe子页面中调用显示和隐藏遮罩层。

示例代码:

index.html

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

  
  
  
  
  
HTML遮罩层  
  
  
  
    

HTML遮罩层使用

index.css

CSS Code复制内容到剪贴板

* {   
    margin: 0;   
    padding: 0;   
}   
  
html, body {   
    width: 100%;   
    height: 100%;   
    font-size: 14px;   
}   
  
p.header {   
    width: 100%;   
    height: 100px;   
    border-bottom: 1px dashed blue;   
}   
  
p.title-outer {   
    position: relative;   
    top: 50%;   
    height: 30px;   
}   
span.title {   
    text-align: left;   
    position: relative;   
    left: 3%;   
    top: -50%;   
    font-size: 22px;   
}   
  
p.body {   
    width: 100%;   
}   
.overlay {   
    position: absolute;   
    top: 0px;   
    left: 0px;   
    z-index: 10001;   
    display:none;   
    filter:alpha(opacity=60);   
    background-color: #777;   
    opacity: 0.5;   
    -moz-opacity: 0.5;   
}   
.loading-tip {   
    z-index: 10002;   
    position: fixed;   
    display:none;   
}   
.loading-tip img {   
    width:100px;   
    height:100px;   
}   
  
.modal {   
    position:absolute;   
    width: 600px;   
    height: 360px;   
    border: 1px solid rgba(0, 0, 0, 0.2);   
    box-shadow: 0px 3px 9px rgba(0, 0, 0, 0.5);   
    display: none;   
    z-index: 10003;   
    border-radius: 6px;   
}

index.js

JavaScript Code复制内容到剪贴板

function rightIFrameLoad(iframe) {   
    var pHeight = getWindowInnerHeight() - $('#header').height() - 5;   
       
    $('p.body').height(pHeight);   
    console.log(pHeight);   
       
}   
  
// 浏览器兼容 取得浏览器可视区高度   
function getWindowInnerHeight() {   
    var winHeight = window.innerHeight   
            || (document.documentElement && document.documentElement.clientHeight)   
            || (document.body && document.body.clientHeight);   
    return winHeight;   
       
}   
  
// 浏览器兼容 取得浏览器可视区宽度   
function getWindowInnerWidth() {   
    var winWidth = window.innerWidth   
            || (document.documentElement && document.documentElement.clientWidth)   
            || (document.body && document.body.clientWidth);   
    return winWidth;   
       
}   
  
/** 
 * 显示遮罩层  
 */  
function showOverlay() {   
    // 遮罩层宽高分别为页面内容的宽高   
    $('.overlay').css({'height':$(document).height(),'width':$(document).width()});   
    $('.overlay').show();   
}   
  
/** 
 * 显示Loading提示  
 */  
function showLoading() {   
    // 先显示遮罩层   
    showOverlay();   
    // Loading提示窗口居中   
    $("#loadingTip").css('top',   
            (getWindowInnerHeight() - $("#loadingTip").height()) / 2 + 'px');   
    $("#loadingTip").css('left',   
            (getWindowInnerWidth() - $("#loadingTip").width()) / 2 + 'px');   
               
    $("#loadingTip").show();   
    $(document).scroll(function() {   
        return false;   
    });   
}   
  
/** 
 * 隐藏Loading提示  
 */  
function hideLoading() {   
    $('.overlay').hide();   
    $("#loadingTip").hide();   
    $(document).scroll(function() {   
        return true;   
    });   
}   
  
/** 
 * 模拟弹出模态窗口p  
 * @param innerHtml 模态窗口HTML内容  
 */  
function showModal(innerHtml) {   
    // 取得显示模拟模态窗口用p   
    var dialog = $('#modalp');   
       
    // 设置内容   
    dialog.html(innerHtml);   
       
    // 模态窗口p窗口居中   
    dialog.css({   
        'top' : (getWindowInnerHeight() - dialog.height()) / 2 + 'px',   
        'left' : (getWindowInnerWidth() - dialog.width()) / 2 + 'px'  
    });   
       
    // 窗口p圆角   
    dialog.find('.modal-container').css('border-radius','6px');   
       
    // 模态窗口关闭按钮事件   
    dialog.find('.btn-close').click(function(){   
        closeModal();   
    });   
       
    // 显示遮罩层   
    showOverlay();   
       
    // 显示遮罩层   
    dialog.show();   
}   
  
/** 
 * 模拟关闭模态窗口p  
 */  
function closeModal() {   
    $('.overlay').hide();   
    $('#modalp').hide();   
    $('#modalp').html('');   
}

body.html

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

  
  
  
  
  
body 页面  
  
  
  
  
    

模态窗口1

运行结果:

初始化

HTML中怎么使用遮罩层

显示遮罩层和Loading提示

HTML中怎么使用遮罩层

显示遮罩层和模拟弹出模态窗口

HTML中怎么使用遮罩层

感谢各位的阅读!关于HTML中怎么使用遮罩层就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!


新闻名称:HTML中怎么使用遮罩层
分享链接:http://scyingshan.cn/article/jcihhh.html