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


Posted in Javascript onOctober 26, 2017

本文实例为大家分享了js自定义弹出窗口效果展示的具体代码,供大家参考,具体内容如下

效果图:

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

源码:

1.demo.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>自定义弹出窗口</title>
  <script type="text/javascript" src="js/myLayer.js"></script>
  <style type="text/css">
    button{
      width: 50px;
      height: 50px;
      border: 1px solid blue;
      background-color: blue;
      color: red;
      border-radius: 5px;
      -webkit-box-shadow: 2px 2px 2px gray;
      -moz-box-shadow: 2px 2px 2px gray ;
      box-shadow: 2px 2px 2px gray ;
    }
    button:hover{
      background-color: green;
      cursor: pointer;
    }
  </style>
  <script type="text/javascript">
    function openWindow() {
      new MyLayer({
        top:"10%",
        left:"10%",
        width:"80%",
        height:"80%",
        title:"我的标题",
        content:"操作成功"
      }).openLayer();
    }
  </script>
</head>
<body>
  <button type="button" onclick="openWindow()">打开弹窗</button>
</body>
</html> 

2.myLayer.js

/**
 * Created by zhuwenqi on 2017/6/16.
 */
/**
 * @param options 弹窗基本配置信息
 * @constructor 构造方法
 */
function MyLayer(options) {
  this.options = options ;
}
/**
 * 打开弹窗
 */
MyLayer.prototype.openLayer = function () {
  var background_layer = document.createElement("div");
  background_layer.style.display = "none";
  background_layer.style.position = "absolute";
  background_layer.style.top = "0px";
  background_layer.style.left = "0px";
  background_layer.style.width = "100%";
  background_layer.style.height = "100%";
  background_layer.style.backgroundColor = "gray";
  background_layer.style.zIndex = "1001";
  background_layer.style.opacity = "0.8" ;
  var open_layer = document.createElement("div");
  open_layer.style.display = "none";
  open_layer.style.position = "absolute";
  open_layer.style.top = this.options.top === undefined ? "10%" : this.options.top;
  open_layer.style.left = this.options.left === undefined ? "10%" :this.options.left;
  open_layer.style.width = this.options.width === undefined ? "80%" : this.options.width;
  open_layer.style.height = this.options.height === undefined ? "80%" : this.options.height;
  open_layer.style.border = "1px solid lightblue";
  open_layer.style.borderRadius = "15px" ;
  open_layer.style.boxShadow = "4px 4px 10px #171414";
  open_layer.style.backgroundColor = "white";
  open_layer.style.zIndex = "1002";
  open_layer.style.overflow = "auto";
  var div_toolBar = document.createElement("div");
  div_toolBar.style.textAlign = "right";
  div_toolBar.style.paddingTop = "10px" ;
  div_toolBar.style.backgroundColor = "aliceblue";
  div_toolBar.style.height = "40px";
  var span_title = document.createElement("span");
  span_title.style.fontSize = "18px";
  span_title.style.color = "blue" ;
  span_title.style.float = "left";
  span_title.style.marginLeft = "20px";
  var span_title_content = document.createTextNode(this.options.title === undefined ? "" : this.options.title);
  span_title.appendChild(span_title_content);
  div_toolBar.appendChild(span_title);
  var span_close = document.createElement("span");
  span_close.style.fontSize = "16px";
  span_close.style.color = "blue" ;
  span_close.style.cursor = "pointer";
  span_close.style.marginRight = "20px";
  span_close.onclick = function () {
    open_layer.style.display = "none";
    background_layer.style.display = "none";
  };
  var span_close_content = document.createTextNode("关闭");
  span_close.appendChild(span_close_content);
  div_toolBar.appendChild(span_close);
  open_layer.appendChild(div_toolBar);
  var div_content = document.createElement("div");
  div_content.style.textAlign = "center";
  var content_area = document.createTextNode(this.options.content === undefined ? "" : this.options.content);
  div_content.appendChild(content_area);
  open_layer.appendChild(div_content);
  document.body.appendChild(open_layer);
  document.body.appendChild(background_layer);
  open_layer.style.display = "block" ;
  background_layer.style.display = "block";
};

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
jQuery选择器用法实例详解
Dec 17 Javascript
javascript瀑布流式图片懒加载实例解析与优化
Feb 23 Javascript
基于JS如何实现给字符加千分符(65,541,694,158)
Aug 03 Javascript
Vue.js框架路由使用方法实例详解
Aug 25 Javascript
IntersectionObserver实现图片懒加载的示例
Sep 29 Javascript
微信小程序选择图片和放大预览图片功能
Nov 02 Javascript
JS实现中英文混合文字溢出友好截取功能
Aug 06 Javascript
初探Vue3.0 中的一大亮点Proxy的使用
Dec 06 Javascript
10种JavaScript最常见的错误(小结)
Jun 21 Javascript
vue发送websocket请求和http post请求的实例代码
Jul 11 Javascript
Vue 按照创建时间和当前时间显示操作(刚刚,几小时前,几天前)
Sep 10 Javascript
ant design vue中日期选择框混合时间选择器的用法说明
Oct 27 Javascript
Vue 兄弟组件通信的方法(不使用Vuex)
Oct 26 #Javascript
JS手机端touch事件计算滑动距离的方法示例
Oct 26 #Javascript
JavaScript实现二叉树的先序、中序及后序遍历方法详解
Oct 26 #Javascript
JavaScript实现树的遍历算法示例【广度优先与深度优先】
Oct 26 #Javascript
详述 Sublime Text 打开 GBK 格式中文乱码的解决方法
Oct 26 #Javascript
node.js的exports、module.exports与ES6的export、export default深入详解
Oct 26 #Javascript
详解Webstorm 新建.vue文件支持高亮vue语法和es6语法
Oct 26 #Javascript
You might like
PHP spl_autoload_register实现自动加载研究
2011/12/06 PHP
header跳转和include包含问题详解
2012/09/08 PHP
thinkPHP js文件中U方法不被解析问题的解决方法
2016/12/05 PHP
动手学习无线电
2021/03/10 无线电
javascript call和apply方法
2008/11/24 Javascript
网站导致浏览器崩溃的原因总结(多款浏览器) 推荐
2010/04/15 Javascript
javascript setAttribute, getAttribute 在不同浏览器上的不同表现
2010/08/05 Javascript
ASP.NET jQuery 实例15 通过控件CustomValidator验证CheckBoxList
2012/02/03 Javascript
JavaScript Math.round() 方法
2015/12/18 Javascript
js重写方法的简单实现
2016/07/10 Javascript
angularjs 中$apply,$digest,$watch详解
2016/10/13 Javascript
jQuery图片切换动画特效
2016/11/02 Javascript
微信小程使用swiper组件实现图片轮播切换显示功能【附源码下载】
2017/12/12 Javascript
vue.js层叠轮播效果的实例代码
2018/11/08 Javascript
关于微信小程序登录的那些事
2019/01/08 Javascript
[01:45]亚洲邀请赛互动指南虚拟物品介绍
2015/01/30 DOTA
python Django模板的使用方法(图文)
2013/11/04 Python
Python三元运算实现方法
2015/01/12 Python
Windows中安装使用Virtualenv来创建独立Python环境
2016/05/31 Python
Pandas 合并多个Dataframe(merge,concat)的方法
2018/06/08 Python
Python面向对象类的继承实例详解
2018/06/27 Python
python学习——内置函数、数据结构、标准库的技巧(推荐)
2019/04/18 Python
django数据模型(Model)的字段类型解析
2019/12/25 Python
Python Numpy,mask图像的生成详解
2020/02/19 Python
Win10下配置tensorflow-gpu的详细教程(无VS2015/2017)
2020/07/14 Python
解析python 类方法、对象方法、静态方法
2020/08/15 Python
python palywright库基本使用
2021/01/21 Python
HTML5 canvas基本绘图之绘制线段
2016/06/27 HTML / CSS
苹果美国官方商城:Apple美国
2016/08/24 全球购物
三星英国官网:Samsung英国
2018/09/25 全球购物
汽车制造与装配专业自荐信范文
2014/01/02 职场文书
士力架广告词
2014/03/20 职场文书
《四季》教学反思
2014/04/08 职场文书
销售员试用期自我评价
2014/09/15 职场文书
给男朋友的道歉短信
2015/05/12 职场文书
Python实现自动玩连连看的脚本分享
2022/04/04 Python