700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > HTML实现遮罩层办法 HTML中如何使用遮罩层【HTML】

HTML实现遮罩层办法 HTML中如何使用遮罩层【HTML】

时间:2024-04-03 06:33:27

相关推荐

HTML实现遮罩层办法 HTML中如何使用遮罩层【HTML】

web前端|html教程

HTML实现遮罩层,HTML使用遮罩层

web前端-html教程

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

韩国网站源码下载,ubuntu卷文件空间,天猫爬虫php,php filetozip,搜排seolzw

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

短信app源码,vscode php跳转,ubuntu本地装gcc,tomcat 支持语言,sQLite的指标,magento 品牌 插件,前端技术框架有什么,小说爬虫app,于安 php,锚文本 seo,免数据电影网站源码,茉莉qq机器人网页,苗木网php模板,公告页面源码,个人通讯录管理系统源码,企业网站程序模板lzw

示例代码:

php个人视频网站源码,vscode插件移动端,ubuntu 如何休眠,tomcat请求参数xss,爬虫日常,php获取月份时间戳,山东seo推广咨询热线,discuz旅游网站源码,用html设计信息手机网页模板lzw

index.html

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

HTML遮罩层

HTML遮罩层使用

index.css

CSS Code复制内容到剪贴板

* {

margin: 0;

padding: 0;

}

html, body {

width: 100%;

height: 100%;

font-size: 14px;

}

div.header {

width: 100%;

height: 100px;

border-bottom: 1px dashed blue;

}

div.title-outer {

position: relative;

top: 50%;

height: 30px;

}

span.title {

text-align: left;

position: relative;

left: 3%;

top: -50%;

font-size: 22px;

}

div.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;

$(‘div.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;

});

}

/**

* 模拟弹出模态窗口DIV

* @param innerHtml 模态窗口HTML内容

*/

function showModal(innerHtml) {

// 取得显示模拟模态窗口用DIV

var dialog = $(‘#modalDiv’);

// 设置内容

dialog.html(innerHtml);

// 模态窗口DIV窗口居中

dialog.css({

‘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复制内容到剪贴板

body 页面* { 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%; }

function showOverlay() {// 调用父窗口显示遮罩层和Loading提示window.top.window.showLoading();

// 使用定时器模拟关闭Loading提示setTimeout(function() { window.top.window.hideLoading();}, 3000);

}

function showModal() {// 调用父窗口方法模拟弹出模态窗口window.top.showModal($(‘#modalContent’).html()); }

模态窗口1

运行结果:

初始化

显示遮罩层和Loading提示

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

原文:/haoqipeng/p/html-overlay.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。