![遮罩层点击按钮弹出并且具有拖动和关闭效果(两种方法)【jquery】](https://700zi.400zi.cn/uploadfile/img/14/552/b7ad15f02d7d6d952f10b2bd63ee9a8d.jpg)
web前端|js教程
点击按钮弹出遮罩层,点击弹出遮罩层,jquery弹出遮罩层,js弹出遮罩层
web前端-js教程
首先给大家展示演示效果:
易语言恶搞源码下载,vscode设置侧边栏大小,ubuntu挂载scsi,tomcat利用多核cpu,爬虫开发手册,php获取不到ip,seo收集关键词公司,下载网站代码 工具,静态影视网站模板lzw
网络注册源码下载,vscode设置php断点,ubuntu 暗转rpm,tomcat的默认url,sqlite数据库V5,爬虫 动物,xml 特殊字符 php,品牌seo系统招商,ecshop手机版网站,脚本ppt模板lzw
基于JavaScript的网页弹出层,鼠标按在弹出层的标题栏处,可以拖动该浮动层随意移动位置,不需要时也可以关闭,操作体验舒服,兼容性好,IE/火狐等众多浏览器下运行稳定、反应快速。代码表现方面,简洁务实,不玩虚的,拿去学习也相当不错。
挂靠网网站源码,安装ubuntu在grub,tomcat不释放端口号,爬虫都有什么生肖,学习php最好的图文网站技术,seo营销加盟lzw
js代码
示例一:
弹出层并可拖拽html,body{height:100%;overflow:hidden;}body,div,h2{margin:0;padding:0;}body{font:12px/1.5 Tahoma;}li{ list-style-type:none}center{padding-top:10px;}button{cursor:pointer;}#overlay{position:absolute;top:0;left:0;width:100%;height:100%;background:#000;opacity:0.5;filter:alpha(opacity=50);display:none;}#win{position:absolute;top:50%;left:50%;width:400px;height:200px;background:#fff;border:4px solid #f90;margin:-102px 0 0 -202px;display:none;}h2{font-size:12px;height:18px;text-align:right;background:#FC0;border-bottom:3px solid #f90;padding:5px;cursor:move;}h2 span{color:#f90;cursor:pointer;background:#fff;border:1px solid #f90;padding:0 2px;}window.onload = function (){var oWin = document.getElementById("win");var oLay = document.getElementById("overlay");var oBtn = document.getElementsByTagName("button")[0];var oClose = document.getElementById("close");var oH2 = oWin.getElementsByTagName("h2")[0];var bDrag = false;var disX = disY = 0;oBtn.onclick = function (){oLay.style.display = "block";oWin.style.display = "block"};oClose.onclick = function (){oLay.style.display = "none";oWin.style.display = "none"};oClose.onmousedown = function (event){(event || window.event).cancelBubble = true;};oH2.onmousedown = function (event){var event = event || window.event;bDrag = true;disX = event.clientX - oWin.offsetLeft;disY = event.clientY - oWin.offsetTop;this.setCapture && this.setCapture();return false};document.onmousemove = function (event){if (!bDrag) return;var event = event || window.event;var iL = event.clientX - disX;var iT = event.clientY - disY;var maxL = document.documentElement.clientWidth - oWin.offsetWidth;var maxT = document.documentElement.clientHeight - oWin.offsetHeight;iL = iL maxL ? maxL : iL;iT = iT maxT ? maxT : iT;oWin.style.marginTop = oWin.style.marginLeft = 0;oWin.style.left = iL + "px";oWin.style.top = iT + "px";return false};document.onmouseup = window.onblur = oH2.onlosecapture = function (){bDrag = false;oH2.releaseCapture && oH2.releaseCapture();};};
×CSS3和Html5图表与图形
jq代码:
代码示例二:
jQuery弹出层效果.black_overlay{display: none;position: absolute;top: 0%;left: 0%;width: 100%;height: 100%;background-color: black;z-index:1001;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);}.white_content {display: none;position: absolute;top: 10%;left: 10%;width: 80%;height: 80%;border: 16px solid lightblue;background-color: white;z-index:1002;overflow: auto;}.white_content_small {display: none;position: absolute;top: 20%;left: 30%;width: 40%;height: 50%;border: 16px solid lightblue;background-color: white;z-index:1002;overflow: auto;}//弹出隐藏层function ShowDiv(show_div,bg_div){document.getElementById(show_div).style.display=lock;document.getElementById(bg_div).style.display=lock ;var bgdiv = document.getElementById(bg_div);bgdiv.style.width = document.body.scrollWidth;// bgdiv.style.height = $(document).height();$("#"+bg_div).height($(document).height());};//关闭弹出层function CloseDiv(show_div,bg_div){document.getElementById(show_div).style.display=
one;document.getElementById(bg_div).style.display=
one;};
关闭
目前来说,我还是喜欢这个自己改造的弹出层。自己在项目中也用的是这个。
以上通过jq和js分别实现了遮罩层点击按钮弹出并且具有拖动和关闭效果,希望对大家有所帮助。