The example in this article describes how jQuery can achieve the effect of popping up the Div layer window by clicking on it. Share it with everyone for your reference. The details are as follows:
This is a draggable and closeable pop-up box effect implemented by jquery. There are many similar effects on the Internet. It is not difficult to achieve this effect on the web page. Now we have jquery for us to use, which is more convenient. Okay, this code demonstrates how to implement a closeable pop-up window by combining CSS code, JavaScript code and HTML. Click the close button with the mouse to close it, and then the open button will be displayed. Click this button. This layer window pops up.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-close-able-alert-dlg-style-codes/
The specific code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>windows</title> <style> #main{position: absolute;top: 10%;left: 10%;} #title{width: 500px;height: 19px;border-top: #85ABE4 1px solid;border-right: #222 1px solid;border-left: #85ABE4 1px solid;border-bottom: none;background: #5B8BD9;} #content{border: #85ABE4 1px solid;border-top: none;width: 500px;height: 300px;} #content img{width: 500px;height: 300px;} #off{float: right;cursor: pointer;} .none{display: none;} .show{display: block;} #open{background: #fff;border: #555 1px solid;height: 13px;width: 50px;position: absolute;left: 50px;top: 400px;cursor: pointer;} #open marquee{font-size: 12px;color: #555;} #img{background: url(images/s.jpg) no-repeat;float: right;width: 49px;height: 19px;} #img: hover{background: url(images/sh.jpg) no-repeat;} #ten{float: left;width: 400px;} </style> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //设置标题栏 document.title="0.0 WINDOW"; //窗口的拖动 var bool=false; var offsetX=0; var offsetY=0; $("#main").mousedown(function(){ bool=true; offsetX = event.offsetX; offsetY = event.offsetY; $("#ten").css('cursor','move'); }) .mouseup(function(){ bool=false; }) $(document).mousemove(function(e){ if(!bool) return; var x = event.clientX-offsetX; var y = event.clientY-offsetY; $("#main").css("left", x); $("#main").css("top", y); }) //窗口的关闭 $("#img").click(function() { $("#main").removeClass("show"); $("#main").addClass("none"); $("#open").addClass("show"); }); $("#open").click(function() { $("#main").removeClass("none"); $("#main").addClass("show"); $("#open").removeClass("show"); $("#open").addClass("none"); }); }); </script> </head> <body> <div id="main" class="show"> <div id="title"> <div id="ten"></div> <div id="img" title="close"></div> </div> <div id="content"> </div> </div> <div id="open" class="none" title=""> <marquee>点击弹出窗口</marquee> </div> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.