html Modal popup(html 模态弹出窗口)
问题描述
如何为以下代码制作一个简单的模式弹出窗口.点击背景时,模式弹出窗口不应该消失.
How to make a simple modal popup for the following code.And on click on the background the modal popup should not disappear.
<html>
<input type="textarea"></input>
</html>
推荐答案
这是一个纯 JavaScript 示例:
Here's a plain-JavaScript example:
var modal = document.getElementById('modal');
var shade = document.getElementById('shade');
document.getElementById('start').onclick = function() {
modal.style.display = shade.style.display = 'block';
};
document.getElementById('close').onclick = function() {
modal.style.display = shade.style.display = 'none';
};
// This code is a workaround for IE6's lack of support for the
// position: fixed style.
//
if (!('maxHeight' in document.body.style)) {
function modalsize() {
var top = document.documentElement.scrollTop;
var winsize = document.documentElement.offsetHeight;
var docsize = document.documentElement.scrollHeight;
shade.style.height = Math.max(winsize, docsize) + 'px';
modal.style.top = top + Math.floor(winsize / 3) + 'px';
};
modal.style.position = shade.style.position = 'absolute';
window.onscroll = window.onresize = modalsize;
modalsize();
}
body {
margin: 0;
}
#shade,
#modal {
display: none;
}
#shade {
position: fixed;
z-index: 100;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#modal {
position: fixed;
z-index: 101;
top: 33%;
left: 25%;
width: 50%;
}
#shade {
background: silver;
opacity: 0.5;
filter: alpha(opacity=50);
}
<div id="shade"></div>
<div id="modal">
<textarea rows="5" cols="25"></textarea>
<button id="close">Close</button>
</div>
<p>
<button id="start">Start</button>
</p>
您可以从那里进行各种改进,例如修复 IE z-indexing 的 iframe hack,或将其封装在可重用对象中,但这是完成的基本方式.
There are various improvements you can make from there, such as iframe hacks to fix IE z-indexing, or encapsulating it in a reusable object, but that's the basic way it's done.
这篇关于html 模态弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:html 模态弹出窗口
基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01