兼容web端和手机端的弹窗插件,(弹窗内可滑动,并可阻止下面的页面滑动)
来源:互联网 发布:bestv安装第三方软件 编辑:程序博客网 时间:2024/06/01 08:07
前言
电脑端、手机端通用弹窗插件,原生js编写。允许弹窗内部滚动,同时,防止弹窗下面的页面滚动。
一、js内容
popup: { isInit: false, isOpen: false, parseDom: function(str){ var div = document.createElement("div"); div.innerHTML = str; return div.childNodes; }, init: function(width, height){ var popHtml = "<div class='popup' style='width:100%;height:100%; z-index: 9999;-webkit-transition: all ease 700ms;" + "position: fixed;top:0;left: 0;background-color: rgba(0,0,0,0.8);display: none;'>"+ "<div class='middle' style='display: table-cell;vertical-align: middle;text-align: center;'>"+ "<div class='inner' style='display: inline-block;'>"+ "<div class='content' style='width:"+ width + ";height:" + height + ";background-color:white;word-break: break-all;-webkit-overflow-scrolling:touch;box-sizing:border-box;color: black;padding:20px;position:relative;'></div>"+ "</div>"+ "</div>"+ "</div>"; document.body.appendChild(this.parseDom(popHtml)[0]); this.isInit = true; },/*width: 弹窗宽度 height:弹窗高度contentHtml:弹窗内容*/ toast: function(width, height, contentHtml){ if(!this.isInit){ this.init(width, height); } this.isOpen = true; var content = document.querySelector(".popup .middle .inner .content"); content.innerHTML = contentHtml; document.querySelector(".popup").style.display = "table"; var viewPortWidth = document.documentElement.clientWidth; if(viewPortWidth > 600){ //web端,防止下部页面滑动 document.body.style.overflow = "hidden"; }else{ //手机端,防止下部页面滑动,其中,country_detail为页面最顶层的元素,包含除了弹窗以外的其他所有内容 document.querySelector(".country_detail").style.position = "fixed"; } }, close: function(){ this.isOpen = false; document.body.style.overflow = "scroll"; //允许web端弹窗下面页面滚动 document.querySelector(".country_detail").style.position = "relative"; //允许web端弹窗下面页面滚动 document.querySelector(".popup").style.display = "none"; }, }
二、使用方法
popup.toast("722px","424px",html); html为你要添加的页面片段,css方面,你在其中添加了什么,就对相应的内容添加样式文件,比如:html为<div class="center">ddd</div>, 则添加的样式为.popup .center{}
三、实际使用展示如下:
web端:
手机端:
阅读全文
0 0
- 兼容web端和手机端的弹窗插件,(弹窗内可滑动,并可阻止下面的页面滑动)
- 移动端禁止遮罩层下面的页面滑动
- 微信浏览器弹出框滑动时页面跟着滑动(兼容Android和IOS端)
- 可滑动手机日期插件
- 手机网站表层div滑动,导致底层body滑动(touchmove的阻止)
- 手机端滑动插件swiper3.x的使用示例
- 如何阻止h5body的滑动
- 阻止浏览器自身滑动事件 例如苹果手机的上拉下拉滑动
- 基于jq的图片轮播插件,滑动切图,兼容移动,PC端
- 【web】页面缩放和滑动功能实现的方法总结
- 移动端阻止屏幕滑动
- 可滑动的viewpagerIndicator
- ViewPager左右滑动页面,下面的按钮跟着动态变化
- 手机端弹出层弹出后,下面禁止滑动
- 自定义可点击和滑动的按钮
- Mobiscroll的介绍【一款兼容PC和移动设备的滑动插件】
- 可滑动的窗口的内部Div可独立滑动,并将内部Div滑动条隐藏
- Viewpager和SeekBar的滑动冲突的解决办法(其他滑动冲突可参考)
- Android 中的AndroidManifest.xml文件中的代码解释
- ssh免秘钥配置及错误解决
- 小结 | 一维数组,二维数组
- 正则表达式学习笔记
- xps-15-9550安装win10、linux双系统
- 兼容web端和手机端的弹窗插件,(弹窗内可滑动,并可阻止下面的页面滑动)
- 链表倒置
- WebView加载URL配置
- 文章标题
- 获取文本文件Mime Type
- 【Oracle学习笔记】使用Oracle11g中的sqldeveloper
- 用vue构建项目笔记2(引入自定义头部组件)
- mysql java.sql.SQLException: Unknown system variable 'language
- LoRaWAN协议中文版 第10章 Class B 模式的上行帧