JS来添加弹出层,并且完成锁屏
上图
<html>
<head>
<title>弹出层</title>
<style type="text/css">
*{
padding:0px;
margin:0px;
}
.up{
width:500px;
height: 400px;
border:1px solid silver;
position: absolute;
display: none;
z-index: ;
background:#fff;
/* top:50%;
left: 50%;*/
/* margin-left: -250px;
margin-top: -200px;*/
}
.up h2{
background-color: #f2f2f2;
text-align: center;
}
.con span{
width:20px;
height:30px;
text-align: center;
line-height: 30px;
background-color:red;
cursor: pointer;
}
.mask{
width:3000px;
height: 3000px;
background:#;
opacity: 0.3;
position: absolute;
top:;
left: ;
z-index: ;
display:none;
}
</style>
</head>
<body>
<div class="con">
<span id="open">打开弹出层</span>
</div>
<div class="up" id="up">
<h2>弹出层效果</h2>
<span id="close">关闭</span>
</div>
<img src="a.jpg"> </body>
<script type="text/javascript">
//两种方式实现div居中:1:用css方式:top:50%,left:50%; margin-let:-divwidth/2 margin-top:divheight/2; 2:用js实现:获取窗口的高宽,top=(屏幕高-div高)/2,为了随时的监听浏览器的改变,需要用到浏览器事件 window.onload=function(){
function $(id){
return document.getElementById(id);
}
//将div的位置封装在一个函数内部,直接调用
function myDiv(){
var mTop=(document.documentElement.clientHeight-)/;
var mleft=(document.documentElement.clientWidth-)/;
$("up").style.top=mTop+"px";
$("up").style.left=mleft+"px";
}
myDiv();
$("open").onclick=function(){
$("up").style.display="block";
mask.style.display="block"; }
$("close").onclick=function(){
$("up").style.display="none";
mask.style.display="none"
}
//创建一个DIV
var mask=document.createElement("div");
// //给这个DIV一个id和class属性
// mask.id="mask";
mask.className="mask";
mask.style.width=document.documentElement.clientWidth;
mask.style.height=document.documentElement.clientHeight;
//将这个DIV放置到body里面--》一般是:父节点.appendChild(子节点)
//这里注意的是absolute,要设置top和left;
document.body.appendChild(mask); //屏幕改变大小的时候,div不会自动的改变,需要添加窗口改变事件
window.onresize=function(){
myDiv();
mask.style.width=document.documentElement.clientWidth;
mask.style.height=document.documentElement.clientHeight;
}
}
</script>
</html>
JS来添加弹出层,并且完成锁屏的更多相关文章
- js进阶 11-20 弹出层如何制作
js进阶 11-20 弹出层如何制作 一.总结 一句话总结:其实就是一个div,控制显示和隐藏即可.设置成绝对定位更好,就可以控制弹出层出现的位置.关闭的画质需要将display重新设置为none就好 ...
- 在vue中继续使用layer.js来做弹出层---切图网
layer.js是一个方便的弹出层插件,切图网专注于PSD2HTML等前端切图多年,后转向Vue开发.在vue开发过程中引入layer.js的时候遇到了麻烦.原因是layer.js不支持import导 ...
- js漂亮的弹出层
1.漂亮的弹出层----artDialog http://aui.github.io/artDialog/ 2.弹出层 ------layer http://sentsin.com/jquery/la ...
- DIV JS CSS 轻量级弹出层 兼容各浏览器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- (三)原生JS实现 - 插件 - 弹出层
创建遮罩层 _createCover: function() { var newMask = document.createElement("div"); newMask.id = ...
- JS简易弹出层
目标 实现简易的js弹出框.为了简单灵活的在小项目中使用. 实现思路 研究bootstrap的弹出框效果后,认为层级示意图如下: 层说明 弹出层分为三层.最底层的遮罩层,覆盖在浏览器视口上.它之上是弹 ...
- JS弹出层遮罩,隐藏背景页面滚动条细节优化
做过弹层组件的童鞋应该都考虑过特殊情况下取消页面滚动条,让其不能滚动,这样用户体验会好很多,当弹层内容超出屏幕展现范围的时候在弹层上面增加滚动条来查看全部内容. 一.去除滚动条方法给body添加ove ...
- 简单 JS 弹出层 背景变暗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 弹出层layer演示 以及在编写弹出层时遇到的错误
实现的功能: 首先第一步 在官方下载layer的文件.layUI官网:http://layer.layui.com/ http://layer.layui.com/ layer文件的下载步骤如 ...
随机推荐
- 【leetcode】Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- 利用cocostudio库函数 实现左右滑动的背包栏UI (cocos2d-x 2.2.0)
.h #ifndef __COMMON_COMPONENTS__ #define __COMMON_COMPONENTS__ #include "cocos2d.h" #inclu ...
- 21.左旋转字符串[LeftRotateString]
[题目] 定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部.如把字符串AB1234 左旋转2位得到字符串1234AB.请实现字符串左旋转的函数.要求时间对长度为n的字符串操作的复杂度 ...
- jquery validate自定义checkbox验证规则和样式
参考:http://blog.csdn.net/xh16319/article/details/9987847 自定义checkbox验证,“检查checkbox是否选中” jQuery.valida ...
- LLVM,Clang
在使用xcode时常常会遇到这2个概念,今天总结一下. wiki中关于llvm的描述: LLVM提供了完整編譯系統的中間層,它會將中間語言(IF, Intermediate form)從編譯器取出與最 ...
- Java for LeetCode 061 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- 【python】一个简单的贪婪爬虫
这个爬虫的作用是,对于一个给定的url,查找页面里面所有的url连接并依次贪婪爬取 主要需要注意的地方: 1.lxml.html.iterlinks() 可以实现对页面所有url的查找 2.获取页面 ...
- [Linux] Linux进程PID散列表
linux系统中每个进程由一个进程id标识,在内核中对应一个task_struct结构的进程描述符,系统中所有进程的task_struct通过链表链接在一起,在内核中,经常需要通过进程id来获取进程描 ...
- Json简介与转换数据例子
Json是什么,Json就是javascript对象或者数组格式的字符串,Http协议不能传递JavaScript对象,所以要转换为字符串进行传输.AJAX传递复杂数据如果自己进行格式定义的话会经历组 ...
- php 简单操作数据库
<?php header("content-type:text/html;charset=utf-8"); /*//造一个连接 $connect = @mysql_conne ...