<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
<meta charset="UTF-8">
<title>Title</title>
<style>
.modal{
position:fixed;
left:0;
right:0;
top:0;
bottom:0;
background-color:rgba(0,0,0,0.5);
display:none;
z-index:1050;
opacity:0;
transition: all .5s ease-out 0s;
}
.dialog{
width:500px;
height:300px;
position:relative;
box-shadow:0 5px 15px rgba(0,0,0,.5);
border-radius:10px;
background-color:#fff;
margin:30px auto;
transform: translate(0,-40%);
-webkit-transform: translate(0,-40%);
transition: all .5s ease-out 0s;
}
.dialog-header{
box-sizing:border-box;
border-bottom:1px solid #ccc;
}
.dialog-header h3,.dialog-header span{
display:inline-block;
}
.dialog-header span{
float:right;
margin-right:10px;
overflow: hidden;
line-height:58px;
cursor:default;
font-size:18px;
}
.in{
opacity: 1;
}
.in .dialog{
transform: translate(0,0);
-webkit-transform: translate(0,0);
}
</style>
</head>
<body>
<input type="button" value="click" id="btn">
<div style="height: 200px;width: 100%;"> dddddddd</div>
<div style="height: 200px;width: 100%;"> dddddddd</div>
<div style="height: 200px;width: 100%;"> dddddddd</div>
<div style="height: 200px;width: 100%;"> dddddddd</div> <div style="height: 200px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div> <div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div style="height: 20px;width: 100%;"> dddddddd</div>
<div class="modal" id="modal">
<div class="dialog" style="width: 300px;">
<header class="dialog-header">
<h3>this is dialog title</h3>
<span id="close">&times;</span>
</header>
<div class="dialog-content">
this is dialog content
</div>
</div>
</div> <script>
var oBtn = document.getElementById("btn");
var oModal = document.getElementById("modal");
var oClose = document.getElementById("close");
var bodyEl = document.body
oBtn.addEventListener("click", function(){
// 方法1、点开时给body固定定位,关闭时相对定位
// bodyEl.style.position = 'fixed'; oModal.style.display = "block";
// 方法2、给模态窗口添加touchmove事件进行阻止默认行为
oModal.addEventListener('touchmove',function(e){
e.stopPropagation();
e.preventDefault();
})
var timer = setTimeout(function(){
oModal.className = "modal in";
clearTimeout(timer);
},0);
});
oClose.addEventListener("click", function(){
oModal.className = "modal";
var timer = setTimeout(function(){
oModal.style.display = "none";
clearTimeout(timer);
},200);
// bodyEl.style.position = 'relative'
});
//封装=>说明一点,这里用了jquery选择器,也可以替换掉。
/*
* 封装之后可以创建Dialog对象,并且可以配置其位置和大小,在项目中可以在任何地方创建使用,不必每个弹窗都写一遍。
* */
//默认配置
var defaultConfig = {
width:600,
height:300,
top:30
}
function Dialog(config){
this.config = {
id:config.id || 'modal',
width:config.width || 600,
height:config.height || 400,
top:config.top || 30
};
$($('#'+config.id).children()[0]).css({
'width': config.width+"px",
'height': config.height+"px",
'margin-top': config.top+"px"
});
}
Dialog.prototype = {
show: function(){
$('#'+this.config.id).show();
var that = this;
var timer = setTimeout(function(){
$('#'+that.config.id).addClass("in");
clearTimeout(timer);
});
},
hide: function(){
$('#'+this.config.id).removeClass('in');
var that = this;
var timer = setTimeout(function(){
$('#'+that.config.id).hide();
clearTimeout(timer);
}, 200);
}
}
</script>
</body>
</html>

封装dialog弹框的更多相关文章

  1. 解决 jquery dialog 弹框destroy销毁方法不能把弹出元素设置成初始状态

    在使用jquery ui中的dialog弹出窗口的时候遇到一个问题,就是页面弹出窗口关闭后希望表单元素能回到初始状态 例如文本框输入内容后关闭dialog后里面的内容清除,使用了destroy方法也不 ...

  2. jQuery-自己封装的弹框

    (function () { CDK={ cfm:function(resFun,errFun){ var confirm=document.createElement('div'); confirm ...

  3. jquery Dialog弹框插件

    function Dialog(options) { var defaults = { // 默认值. title: '', // 标题文本,若不想显示title请通过CSS设置其display为no ...

  4. easyUI创建dialog弹框

    1.在当前页面必须有一个DIV <!-- 保证金明细的详情列表显示 --> <div id="dialog-alarm-detail"></div&g ...

  5. vue封装一个弹框组件

    这是一个提示框和对话框,例:   这是一个组件 eject.vue <template> <div class='kz-cont' v-show='showstate'> &l ...

  6. jquery Dialog弹框插件使用

    var dialog = new Dialog({ title: '购物车', type: 'url', width: 520, content: "Uplolo.aspx", s ...

  7. Android Dialog弹框提示

    public void showUpdateDialog(String content) { //普通的AlertDialog对话框 AlertDialog.Builder builder = new ...

  8. JQuery EasyUI dialog弹出框的 close 和 destroy

    开发项目中(使用JQuery EasyUI),根据业务需要重叠弹出多个提示框的情况,会出现如下情况:页面出现两个div模块调用同一个弹出页面,页面的数据接受框元素不能实时存储数据解决方案: 使用$(t ...

  9. vue封装公用弹出框方法,实现点击出现操作弹出框

    vue封装公用弹出框方法,实现点击出现操作弹出框 如上图所示,这次要实现一个点击出现操作弹框的效果:并将这个功能封装成一个函数,便于在项目的多个地方使用. 具体思路是: 封装一个组件,组件保护一个插槽 ...

随机推荐

  1. java设计模式-----5、原型模式

    原型(Prototype)模式是一种对象创建型模式,他采取复制原型对象的方法来创建对象的实例.使用原型模式创建的实例,具有与原型一样的数据. 原型模式的特点: 1.由原型对象自身创建目标对象.也就是说 ...

  2. 简单工厂模式使用ResourceBundle读取.properties配置文件

    在做项目时,遇到需要创建DAO.Service等类的实例的时候,想到用工厂方法来运作,而简单工厂方法又有明显的缺点: ①由于工厂类集中了所有实例的创建逻辑,违反了高内聚责任分配原则,将全部创建逻辑集中 ...

  3. Python随笔目录

    Python 一.Python基础 Python入门 数据类型 函数(迭代器生成器三元表达式) 模块和常用内置模块 面向对象 网络编程(socket) 并发编程 ... 二.数据库 MySQL PyM ...

  4. vue项目使用vue-i18n和iView切换多语言

    效果图: 当然,如果使用iview组件,组件也会对应切换语言. 这里,假设已经用vue-cli脚手架创建了项目,熟悉vue-router,而且已经引入了iview UI. 第一步: 我们在main.j ...

  5. PHP开发支付宝之电脑网站支付--流程简介

    前言 前端时间自己开发了一个drupal的支付宝模块,现在整理一下过程,因为支付宝官方网站提供的接口及文档都是新接口的,而且使用新接口的过程比较麻烦一点,所以整理一下 1.支付宝的账号必须经过企业资格 ...

  6. html5 css选择器 井号, 句点的区别

    一.理解CSS的样式组成CSS里的样式表是有规则组成的,每条规则有三个部分组成:1.选择器(如下面例子中的:"body"),告诉浏览器文档的哪个部分受规则影响:2.属性(如实例中的 ...

  7. BootstrapValidator超详细教程

    一.引入必要文件 下载地址:(https://github.com/nghuuphuoc/bootstrapvalidator/archive/v0.4.5.zip) <link rel=&qu ...

  8. 【转载】shell实例手册

    原文地址:shell实例手册  作者:没头脑的土豆 shell实例手册 0说明{ 手册制作: 雪松 更新日期: -- 欢迎系统运维加入Q群: 请使用"notepad++"打开此文档 ...

  9. QTreeView/QTableView中利用QStandardItem实现复选框三种形态变化

    https://www.techieliang.com/2017/12/729/ 原文地址 using_checkbox_item.h /** * @file using_checkbox_item. ...

  10. pmp心得

    我报名比较晚,等缴费最后期限,才缴费,下定决心,开始正式的备考. 我的工作比较忙,备考时间特比较短,从拿到书到考试只有二个月了,心理慌慌的,期间还有一门其他的考试,在5月底,实际时间只能有20来天. ...