下面分享一个js 弹出窗, 分 toast , dialog , load 三种弹窗 , 下面用js css 来实现以下:

首先是js代码 | 采用了 es6 的写法
//公共弹窗加载动画
const DIALOG_TOAST = '1',
DIALOG_DIALOG = '2',
DIALOG_LOAD = '3',
class Dialog {
constructor(type = DIALOG_DIALOG,
dialogContent = '请求失败',
wrapClassName = 'common-dialog-wrap',
dialogWrapClassName = 'common-dialog-content-wrap',
contentClassName = 'common-dialog-content',
btnClassName = 'common-btn',
btnContent = '确定') {
this.type = type;
//吐司
if (type == DIALOG_TOAST) {
this.dialog = document.createElement('div');
this.dialog.className = 'common-toast';
this.dialog.innerHTML = dialogContent;
}
//加载动画
else if (type == DIALOG_LOAD) {
this.dialog = document.createElement('div');
this.dialog.className = wrapClassName;
this.figure = document.createElement('figure');
this.figure.className = 'common-loadGif';
this.img = document.createElement('img');
this.img.src = getAbsolutePath() + '/fenqihui/static/bitmap/travel/loadgif.gif';
this.figure.appendChild(this.img);
this.dialog.appendChild(this.figure);
} else if (type == DIALOG_DIALOG) {
this.dialog = document.createElement('div');
this.dialog.className = wrapClassName;
this.dialogWrap = document.createElement('div');
this.dialogWrap.className = dialogWrapClassName;
this.conetent = document.createElement('p');
this.conetent.innerHTML = dialogContent;
this.conetent.className = contentClassName;
this.confirmButton = document.createElement('p');
this.confirmButton.innerHTML = btnContent;
this.confirmButton.className = btnClassName;
this.dialogWrap.appendChild(this.conetent);
this.dialogWrap.appendChild(this.confirmButton);
this.dialog.appendChild(this.dialogWrap);
this.bindEvent();
}
}
bindEvent() {
this.confirmButton.addEventListener('click', ()=> {
this.hide();
})
}
show(time) {
document.querySelector('body').appendChild(this.dialog);
$(this.dialog).css('display', 'block');
if (this.type == DIALOG_TOAST) {
setTimeout(()=> {
$(this.dialog).css('display', 'none');
}, time);
}
}
hide() {
$(this.dialog).css('display', 'none');
}
}
css 文件如下:
/*公共弹窗*/
.common-dialog-wrap {
position: fixed;
background: rgba(0,0,0,.7);
z-index: 100;
height: 100%;
width: 100%;
top: 0;
}
.common-dialog-content {
height: 2rem;
border-bottom: 1px solid #ccc7c7;
line-height: 2rem;
text-align: center;
font-size: .65rem;
}
.common-btn {
text-align: center;
height: 2rem;
color: orange;
line-height: 2rem;
}
.common-dialog-content-wrap{
background: #fff;
width: 10rem;
height: 4rem;
border-radius: 5px;
position: fixed;
left: 0;
top:0;
right: 0;
bottom: 0;
margin: auto;
}
/*吐司样式*/
.common-toast{
height: 1.6rem;
width: 4rem;
box-sizing: content-box;
color: #fff;
padding: 0 10px;
position: fixed;
left: 0;
top:0;
bottom: 0;
right: 0;
text-align: center;
line-height: 1.6rem;
margin: auto;
background: rgba(0,0,0,.7);
border-radius: 2rem;
}
.common-loadGif{
height: 4rem;
width: 4rem;
position: fixed;
top:0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
.common-loadGif img{
height: 100%;
width: 100%;
border-radius: 10px;
}
使用方式
new Dialog(DIALOG_DIALOG).show() | hide() new Dialog(DIALOG_LOAD).show() | hide() new Dialog(DIALOG_TOAST).show(time : number) | hide()
效果如下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# js弹出框组件
# js弹出组件
# js弹出框
# js简单的弹出框有关闭按钮
# js 弹出框只弹一次(二次修改之后的)
# js 弹出框 替代浏览器的弹出框
# JS 事件绑定、事件监听、事件委托详细介绍
# Javascript 事件流和事件绑定
# 关于JavaScript中事件绑定的方法总结
# 深入理解JS的事件绑定、事件流模型
# JavaScript弹出框与事件绑定的超详细解析
# 加载
# 采用了
# 弹出
# 三种
# 来实现
# 大家多多
# innerHTML
# className
# figure
# img
# loadGif
# div
# btn
# btnClassName
# btnContent
# createElement
# document
# dialogWrap
# travel
# appendChild
相关文章:
教育培训网站制作流程,请问edu教育网站的域名怎么申请?
如何快速上传自定义模板至建站之星?
如何在新浪SAE免费搭建个人博客?
如何通过二级域名建站提升品牌影响力?
如何通过VPS搭建网站快速盈利?
如何用低价快速搭建高质量网站?
广州网站建站公司选择指南:建站流程与SEO优化关键词解析
建站主机服务器选购指南:轻量应用与VPS配置解析
建站为何优先选择香港服务器?
合肥做个网站多少钱,合肥本地有没有比较靠谱的交友平台?
成都网站制作价格表,现在成都广电的单独网络宽带有多少的,资费是什么情况呢?
如何高效搭建专业期货交易平台网站?
如何选购建站域名与空间?自助平台全解析
如何通过智能用户系统一键生成高效建站方案?
如何在Windows虚拟主机上快速搭建网站?
c# 在高并发下使用反射发射(Reflection.Emit)的性能
网站制作说明怎么写,简述网页设计的流程并说明原因?
如何快速搭建高效香港服务器网站?
C++如何编写函数模板?(泛型编程入门)
湖南网站制作公司,湖南上善若水科技有限公司做什么的?
如何选择高效可靠的多用户建站源码资源?
javascript基本数据类型及类型检测常用方法小结
百度网页制作网站有哪些,谁能告诉我百度网站是怎么联系?
在线制作视频的网站有哪些,电脑如何制作视频短片?
c++怎么编写动态链接库dll_c++ __declspec(dllexport)导出与调用【方法】
制作网站软件推荐手机版,如何制作属于自己的手机网站app应用?
建站与域名管理如何高效结合?
,网页ppt怎么弄成自己的ppt?
如何在VPS电脑上快速搭建网站?
威客平台建站流程解析:高效搭建教程与设计优化方案
公司门户网站制作流程,华为官网怎么做?
建站之星多图banner生成与模板自定义指南
如何选择PHP开源工具快速搭建网站?
如何在宝塔面板中创建新站点?
如何通过cPanel快速搭建网站?
如何在服务器上配置二级域名建站?
如何在阿里云完成域名注册与建站?
建站之星如何优化SEO以实现高效排名?
C#怎么创建控制台应用 C# Console App项目创建方法
如何通过虚拟主机快速搭建个人网站?
C++中的Pimpl idiom是什么,有什么好处?(隐藏实现)
企业宣传片制作网站有哪些,传媒公司怎么找企业宣传片项目?
想学网站制作怎么学,建立一个网站要花费多少?
如何在橙子建站上传落地页?操作指南详解
Thinkphp 中 distinct 的用法解析
建站之星安装后如何自定义网站颜色与字体?
最好的网站制作公司,网购哪个网站口碑最好,推荐几个?谢谢?
如何通过服务器快速搭建网站?完整步骤解析
常州企业建站如何选择最佳模板?
如何在阿里云域名上完成建站全流程?
*请认真填写需求信息,我们会在24小时内与您取得联系。