下面分享一个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
相关文章:
微网站制作教程,我微信里的网站怎么才能复制到浏览器里?
建站主机选虚拟主机还是云服务器更好?
如何快速搭建自助建站会员专属系统?
SAX解析器是什么,它与DOM在处理大型XML文件时有何不同?
家庭建站与云服务器建站,如何选择更优?
英语简历制作免费网站推荐,如何将简历翻译成英文?
巅云智能建站系统:可视化拖拽+多端适配+免费模板一键生成
如何在Golang中使用encoding/gob序列化对象_存储和传输数据
行程制作网站有哪些,第三方机票电子行程单怎么开?
高端建站如何打造兼具美学与转化的品牌官网?
建站之星安装需要哪些步骤及注意事项?
,如何利用word制作宣传手册?
如何在Windows虚拟主机上快速搭建网站?
如何快速搭建支持数据库操作的智能建站平台?
如何在Windows环境下新建FTP站点并设置权限?
建站之星体验版:智能建站系统+响应式设计,多端适配快速建站
制作ppt免费网站有哪些,有哪些比较好的ppt模板下载网站?
韩国网站服务器搭建指南:VPS选购、域名解析与DNS配置推荐
C#如何序列化对象为XML XmlSerializer用法
魔方云NAT建站如何实现端口转发?
北京营销型网站制作公司,可以用python做一个营销推广网站吗?
魔毅自助建站系统:模板定制与SEO优化一键生成指南
如何通过西部数码建站助手快速创建专业网站?
宝盒自助建站智能生成技巧:SEO优化与关键词设置指南
如何在新浪SAE免费搭建个人博客?
c++ stringstream用法详解_c++字符串与数字转换利器
如何正确选择百度移动适配建站域名?
如何通过VPS建站实现广告与增值服务盈利?
详解jQuery停止动画——stop()方法的使用
小说建站VPS选用指南:性能对比、配置优化与建站方案解析
建站主机功能解析:服务器选择与快速搭建指南
建站之星Pro快速搭建教程:模板选择与功能配置指南
制作充值网站的软件,做人力招聘为什么要自己交端口钱?
如何获取PHP WAP自助建站系统源码?
合肥做个网站多少钱,合肥本地有没有比较靠谱的交友平台?
网站制作报价单模板图片,小松挖机官方网站报价?
如何高效搭建专业期货交易平台网站?
学生网站制作软件,一个12岁的学生写小说,应该去什么样的网站?
如何解决ASP生成WAP建站中文乱码问题?
c# 在ASP.NET Core中管理和取消后台任务
中山网站推广排名,中山信息港登录入口?
建站之星如何保障用户数据免受黑客入侵?
制作宣传网站的软件,小红书可以宣传网站吗?
如何安全更换建站之星模板并保留数据?
Bpmn 2.0的XML文件怎么画流程图
清除minerd进程的简单方法
如何通过西部建站助手安装IIS服务器?
5种Android数据存储方式汇总
网站制作的软件有哪些,制作微信公众号除了秀米还有哪些比较好用的平台?
已有域名如何快速搭建专属网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。