弹出层总结 和 &n…
来源:互联网 发布:sql server没有服务器 编辑:程序博客网 时间:2024/06/08 05:17
弹出层总结 :实现原理————>
透明遮罩width:100%; height:100%;fixed固定在页面
中间的 div :通过 var clientHeight =document.documentElement.clientHeight; 和
var clientWidth = document.documentElement.clientWidth;
得到页面可视区域宽高,从而设置fixed.
----------------------------------------------------------------------------------------------
那么 该div 就“不会显示”(其实是显示再正常页面以下,只要缩小页面内容就能看见),,,呵呵
而 同为定位的absolute 和 relative 就不会
so 可以利用fixed 这一个特性,,写 弹出层
代码-----------------------------------------------------
#box {
width:980px;height:800px;margin:0auto;border:1px solid #f00;
text-align:center;padding-top:300px;
}
#tanchu1 {
width:100%;height:100%;background:#000;
filter:alpha(opacity:50);opacity:0.5;
position:fixed;top:0px;left:0px;
display:none;
}
#tanchu2{width:400px;height:250px;background:#f00;position:fixed;}
#close {
background:#0f0;float:right;
margin:5px 5px 0px0px;
cursor:pointer;
}
window.onload = function (){
var button =document.getElementByIdx_x_x("input");
var tanchu1 =document.getElementByIdx_x_x("tanchu1");
var close =document.getElementByIdx_x_x("close");
button.onclick = function (){
display();
}
tanchu1.onclick = function (){
hidden();
}
close.onclick = function (){
hidden();
}
}
function display(){
var clientHeight =document.documentElement.clientHeight;
var clientWidth =document.documentElement.clientWidth;
var tanchu2 =document.getElementByIdx_x_x("tanchu2");
var tanchu2Width =getstyle(tanchu2,"width");
var tanchu2Height =getstyle(tanchu2,"height");
tanchu1.style.display ="block";
var s = /\d+/;
var tanchu2Width =tanchu2Width.match(s);
var tanchu2Height =tanchu2Height.match(s);
var tanchu2Top =(clientHeight-tanchu2Height)/2+"px";
var tanchu2Left =(clientWidth-tanchu2Width)/2+"px";
tanchu2.style.top =tanchu2Top;
tanchu2.style.left =tanchu2Left;
}
function hidden(){
tanchu1.style.display ="";
tanchu2.style.top ="";
tanchu2.style.left ="";
}
function getstyle(obj,attr) {通过这个方法,获取对象的样式
if(obj.currentStyle){
returnobj.currentStyle[attr];
}else {
returngetComputedStyle(obj,false)[attr];
}
}
代码截图------------------------------------------------
0 0
- 弹出层总结 和 &n…
- Note 452067.1 &n…
- jcop external&n…
- ExecutionLog2 View -&n…
- JAVA中Action层, Service层&n…
- poj 2739 sum of&n…
- Lesson 55 Not a&n…
- Lesson 57 Can I&n…
- Lesson 59 In or&n…
- 10071 - Back to&n…
- ACM: uva 11210 &n…
- ACM: uva 1325 -&n…
- ACM: uva 1432 -&n…
- ACM: poj 2786 -&n…
- ACM: poj 3972 -&n…
- ACM: uva 1362 -&n…
- ACM: uva 1069 -&n…
- 详解 CSS 属性 -&n…
- 算法题总结之找到数组中出现次数唯一不同的数字
- document.body.scrollTop用…
- JavaScript 正则表达式05
- Java GUI 菜单栏
- 如何升级Windows 10中内置的Ubuntu子系统
- 弹出层总结 和 &n…
- 关于arguments.callee.calle…
- js无缝滚动原理及详解
- css3 属性 transition
- 在python2.7.X中怎么安装numpy scipymatplotlib pandas等模块
- JavaScript qq窗口抖动效果
- css 实现的简单的图片…
- centos mariadb galera 多主同步 haprox keepalive 集群热备
- 使用MFC对FTP文件或者文件夹进行下载、断点续传等功能的个人理解