html5+css3+javascript 自定义弹出窗口

   2023-03-08 学习力0
核心提示:效果图:源码:  1.demo.jsp 1 %@ page contentType="text/html;charset=UTF-8" language="java" % 2 html 3 head 4 title自定义弹出窗口/title 5 script type="text/javascript" src="js/myLayer.js"/script 6 style type="text/css" 7

效果图:

html5+css3+javascript 自定义弹出窗口

源码:

  1.demo.jsp

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <head>
 4     <title>自定义弹出窗口</title>
 5     <script type="text/javascript" src="js/myLayer.js"></script>
 6     <style type="text/css">
 7         button{
 8             width: 50px;
 9             height: 50px;
10             border: 1px solid blue;
11             background-color: blue;
12             color: red;
13             border-radius: 5px;
14             -webkit-box-shadow: 2px 2px 2px gray;
15             -moz-box-shadow: 2px 2px 2px gray ;
16             box-shadow: 2px 2px 2px gray ;
17         }
18         button:hover{
19             background-color: green;
20             cursor: pointer;
21         }
22     </style>
23     <script type="text/javascript">
24         function openWindow() {
25             new MyLayer({
26                 top:"10%",
27                 left:"10%",
28                 width:"80%",
29                 height:"80%",
30                 title:"我的标题",
31                 content:"操作成功"
32             }).openLayer();
33         }
34     </script>
35 </head>
36 <body>
37     <button type="button" onclick="openWindow()">打开弹窗</button>
38 </body>
39 </html>

  2.myLayer.js

 1 /**
 2  * Created by zhuwenqi on 2017/6/16.
 3  */
 4 /**
 5  * @param options 弹窗基本配置信息
 6  * @constructor 构造方法
 7  */
 8 function MyLayer(options) {
 9     this.options = options ;
10 }
11 /**
12  * 打开弹窗
13  */
14 MyLayer.prototype.openLayer = function () {
15     var background_layer = document.createElement("div");
16     background_layer.style.display = "none";
17     background_layer.style.position = "absolute";
18     background_layer.style.top =  "0px";
19     background_layer.style.left = "0px";
20     background_layer.style.width = "100%";
21     background_layer.style.height = "100%";
22     background_layer.style.backgroundColor = "gray";
23     background_layer.style.zIndex = "1001";
24     background_layer.style.opacity = "0.8" ;
25     var open_layer = document.createElement("div");
26     open_layer.style.display = "none";
27     open_layer.style.position = "absolute";
28     open_layer.style.top = this.options.top === undefined ? "10%" : this.options.top;
29     open_layer.style.left = this.options.left === undefined ? "10%" :this.options.left;
30     open_layer.style.width = this.options.width === undefined ? "80%" : this.options.width;
31     open_layer.style.height = this.options.height === undefined ? "80%" : this.options.height;
32     open_layer.style.border = "1px solid lightblue";
33     open_layer.style.borderRadius = "15px" ;
34     open_layer.style.boxShadow = "4px 4px 10px #171414";
35     open_layer.style.backgroundColor = "white";
36     open_layer.style.zIndex = "1002";
37     open_layer.style.overflow = "auto";
38     var div_toolBar = document.createElement("div");
39     div_toolBar.style.textAlign = "right";
40     div_toolBar.style.paddingTop = "10px" ;
41     div_toolBar.style.backgroundColor = "aliceblue";
42     div_toolBar.style.height = "40px";
43     var span_title = document.createElement("span");
44     span_title.style.fontSize = "18px";
45     span_title.style.color = "blue" ;
46     span_title.style.float = "left";
47     span_title.style.marginLeft = "20px";
48     var span_title_content = document.createTextNode(this.options.title === undefined ? "" : this.options.title);
49     span_title.appendChild(span_title_content);
50     div_toolBar.appendChild(span_title);
51     var span_close = document.createElement("span");
52     span_close.style.fontSize = "16px";
53     span_close.style.color = "blue" ;
54     span_close.style.cursor = "pointer";
55     span_close.style.marginRight = "20px";
56     span_close.onclick = function () {
57         open_layer.style.display = "none";
58         background_layer.style.display = "none";
59     };
60     var span_close_content = document.createTextNode("关闭");
61     span_close.appendChild(span_close_content);
62     div_toolBar.appendChild(span_close);
63     open_layer.appendChild(div_toolBar);
64     var div_content = document.createElement("div");
65     div_content.style.textAlign = "center";
66     var content_area = document.createTextNode(this.options.content === undefined ? "" : this.options.content);
67     div_content.appendChild(content_area);
68     open_layer.appendChild(div_content);
69     document.body.appendChild(open_layer);
70     document.body.appendChild(background_layer);
71     open_layer.style.display = "block" ;
72     background_layer.style.display = "block";
73 };

 

 
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • HTML中将背景颜色渐变 html设置背景颜色渐变
    通过使用 css3 渐变可以让背景两个或多个指定的颜色之间显示平稳的过渡,由于用到css3所以需要考虑下浏览器兼容问题,例如:从左到右的线性渐变,且带有透明度的样式:#grad {background: -webkit-linear-gradient(left,rgba(255,0,0,0),rgba(255,0,0,1)); /*
    03-08
  • html5 Canvas 如何自适应屏幕大小
    但是这样创建出的画布不能随着浏览器窗口大小的改变而动态的改变画布的大小。而这一点往往又非常重要, 因为我们会经常改变浏览器窗口大小,不会一直保持某个固定的大小。 html代码 canvas width="300" height="300" id="myCanvas"/canvas设置样式 * {
    03-08
  • Vue中出现Do not use built-in or reserved HTML elements as component id:footer等等vue warn问题
    Vue中出现Do not use built-in or reserved HTM
    错误示图:原因:是因为在本地项目对应文件的script中,属性name出现了错误的命名方式,导致浏览器控制台报错!  诸如: name: header 、  、 name: menu , 等等都属于错误的命名方式等 错误代码命名如下:解决办法:办法1: 如果我们采用正确命名
    03-08
  • HTML在网页中插入音频视频简单的滚动效果
    HTML在网页中插入音频视频简单的滚动效果
    每次上网,打开网页后大家都会看到在网页的标签栏会有个属于他们官网的logo,现在学了HTML了,怎么不会制作这个小logo呢,其实很简单,也不需要死记硬背,每当这行代码出现的时候能知道这是什么意思就ok1 link rel="shortcuticon" type="image/x-icon" href="
    03-08
  • HTML的video标签,不能下载视频代码
    !-- 在线视频不能下载代码 --!DOCTYPE html html headscript src="../Demo/demo/book/JQuery/jQuery v2.2.0.js"/script/headbody div style="text-align:center;"video src="../images/PreviewVideo.mp4" width="820"controls="controls&
    03-08
  • ThinkPHP报错 The requested URL /admin/index/login.html was not found on this server.
    ThinkPHP报错 The requested URL /admin/index/
           解决方案在入口文件夹public下查看.htaccess是否存在。不存在则新建,存在的话,那内容替换为下面这串代码 就可以解决Not Fund#IfModule mod_rewrite.c#Options +FollowSymlinks -Multiviews#RewriteEngine On##RewriteCond %{REQUEST_FILENAME
    03-08
  • HTML特殊字符、列表、表格总结 html特殊符号对
            HTML实体字符  在HTML中一些特殊的字符需要用特殊的方式才能显示出来,比如小于号、版权等,  在课堂上老师教了我们一个有点意思的:空格,在教材上字符实体是“nbsp”通过老师  的演示我们发现不同的浏览器他所显示的效果不同,有的比
    03-08
  • 【JavaScript】使用document.write输出覆盖HTML
    您只能在 HTML 输出中使用 document.write。如果您在文档加载后使用该方法,会覆盖整个文档。分析HTML输出流是指当前数据形式是HTML格式的数据,这部分数据正在被导出、传输或显示,所以称为“流”。通俗的来说就是HTML文档的加载过程,如果遇到document.writ
    03-08
  • ASP.Net MVC 控制@Html.DisplayFor日期显示格式
    在做一個舊表的查詢頁時,遇到一個問題:字段在db里存儲的是DATETIME,但保存的值只有日期,沒有時間數據,比如2018/2/26 0:00:00,顯示出來比較難看,當然也可以做一個ViewModel,在字段上添加Attribute定義來更改名稱和顯示名稱,如下:[Display(Name = "建
    03-08
  • html 基础代码
    title淄博汉企/title/headbody bgcolor="#00CC66" topmargin="200" leftmargin="200" bottommargin="200"a name="top"/a今天br /天气nbsp;nbsp;nbsp;nbsp;nbsp;不错br /font color="#CC0000"格式控制标签br /b 文字加粗方式1\bbr /str
    03-08
点击排行