HTML에서 마스크 레이어를 구현하는 방법 HTML에서 마스크 레이어를 사용하는 방법
이 글에서는 주로 HTML에서 마스크 레이어를 구현하는 방법을 자세히 소개합니다. 웹 페이지에서 마스크 레이어를 사용하면 HTML에서 마스크 레이어를 어떻게 사용할 수 있을까요? 관심 있는 친구들은
웹 페이지에서 마스크 레이어를 사용하면 반복 작업을 방지하고 팝업 모달 창을 시뮬레이션할 수도 있습니다.
구현 아이디어: 하나의 p는 마스크 레이어 역할을 하고, 하나의 p는 로딩되는 동적 GIF 이미지를 표시합니다. 다음 샘플 코드에서는 iframe 하위 페이지에서 표시 및 숨기기 마스크 레이어를 호출하는 방법도 보여줍니다.
샘플 코드:
index.html
XML/HTML 코드클립보드에 콘텐츠 복사
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Commpatible" content="IE=edge"> <title>HTML遮罩层</title> <link rel="stylesheet" href="css/index.css"> </head> <body> <p class="header" id="header"> <p class="title-outer"> <span class="title"> HTML遮罩层使用 </span> </p> </p> <p class="body" id="body"> <iframe id="iframeRight" name="iframeRight" width="100%" height="100%" scrolling="no" frameborder="0" style="border: 0px;margin: 0px; padding: 0px; width: 100%; height: 100%;overflow: hidden;" onload="rightIFrameLoad(this)" src="body.html"></iframe> </p> <!-- 遮罩层p --> <p id="overlay" class="overlay"></p> <!-- Loading提示 p --> <p id="loadingTip" class="loading-tip"> <img src="images/loading.gif" /> </p> <!-- 模拟模态窗口p --> <p class="modal" id="modalp"></p> <script type='text/javascript' src="js/jquery-1.10.2.js"></script> <script type="text/javascript" src="js/index.js"></script> </body> </html>
index.css
CSS 코드클립보드에 콘텐츠 복사
* { 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 코드클립보드에 콘텐츠 복사
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클립보드에 콘텐츠 복사
<!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> <p class='outer'> <p class='inner'> <button id='btnShowLoading' class='button' onclick='showOverlay();'>点击弹出遮罩层</button> <button id='btnShowModal' class='button' onclick='showModal();'>点击弹出模态窗口</button> </p> </p> <!-- 模态窗口内容p,将本页面p内容设置到父窗口p上并模态显示 --> <p id='modalContent' style='display: none;'> <p class='modal-container' style='width: 100%;height: 100%;background-color: white;'> <p style='width: 100%;height: 49px;position: relative;left: 50%;top: 50%;'> <span style='font-size: 36px; width: 100%; text-align:center; display: inline-block; position:inherit; left: -50%;top: -50%;'>模态窗口1</span> </p> <button class='btn-close' style='width: 100px; height: 30px; position: absolute; right: 30px; bottom: 20px;'>关闭</button> </p> </p> <script type='text/javascript' src="js/jquery-1.10.2.js"></script> </body> </html>
실행 결과:
초기화
디스플레이 마스크 레이어 및 로딩 프롬프트
마스크 레이어 표시 및 팝업 모달 창 시뮬레이션
위는 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되기를 바랍니다.
관련 권장사항:
배경 이미지를 HTML의 브라우저 크기에 맞게 조정하세요
위 내용은 HTML에서 마스크 레이어를 구현하는 방법 HTML에서 마스크 레이어를 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











HTML은 간단하고 배우기 쉽고 결과를 빠르게 볼 수 있기 때문에 초보자에게 적합합니다. 1) HTML의 학습 곡선은 매끄럽고 시작하기 쉽습니다. 2) 기본 태그를 마스터하여 웹 페이지를 만들기 시작하십시오. 3) 유연성이 높고 CSS 및 JavaScript와 함께 사용할 수 있습니다. 4) 풍부한 학습 리소스와 현대 도구는 학습 과정을 지원합니다.

HTML은 웹 구조를 정의하고 CSS는 스타일과 레이아웃을 담당하며 JavaScript는 동적 상호 작용을 제공합니다. 세 사람은 웹 개발에서 의무를 수행하고 화려한 웹 사이트를 공동으로 구축합니다.

anexampleStartingtaginhtmlis, whithbeginsaparagraph.startingtagsareessentialinhtmlastheyinitiate rements, definetheirtypes, andarecrucialforstructurituringwebpages 및 smanstlingthedom.

WebDevelopmentReliesonHtml, CSS 및 JavaScript : 1) HtmlStructuresContent, 2) CSSSTYLESIT, 및 3) JAVASCRIPTADDSINGINTERACTIVITY, BASISOFMODERNWEBEXPERIENCES를 형성합니다.

GiteEpages 정적 웹 사이트 배포 실패 : 404 오류 문제 해결 및 해결시 Gitee ...

웹 주석 기능에 대한 Y 축 위치 적응 알고리즘이 기사는 Word 문서와 유사한 주석 기능을 구현하는 방법, 특히 주석 간격을 다루는 방법을 모색합니다 ...

이미지를 클릭 한 후 주변 이미지를 산란 및 확대하는 효과를 얻으려면 많은 웹 디자인이 대화식 효과를 달성해야합니다. 특정 이미지를 클릭하여 주변을 만들 수 있습니다 ...

vue 응용 프로그램을 개발할 때 라우터 폴더 아래에 index.js 파일에 vuerouter를 등록해야 할 필요성이 있으면 종종 라우팅 구성에 문제가 발생합니다. 특별한...
