下面的弹出框组件使用的是类来封装的。一个弹窗组件通过new一个实例来生成。
下面直接上代码:
html结构:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
/*基本的样式*/
button{width: 1.6rem;height: 0.5rem;font-size: 0.3rem;line-height: 0.5rem;background: red;color: white;font-weight: bold}
.hide{display: none;}
.js-pop{
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
top:0;
left: 0;
font-size: 0.24rem;
}
.js-pop .mask{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: 0.2;
}
.js-pop .content{
position: fixed;
top: 50%;
left: 50%;
width: 5.80rem;
height: 4.81rem;
margin: -2.405rem 0 0 -2.9rem;
background: url("pop-bg.png") no-repeat;
background-size: contain;
color: #262626;
text-align: center;
}
.js-pop .content .close{
position: absolute;
top: .25rem;
right: .08rem;
width: .54rem;
height: .48rem;
z-index: 4;
cursor:pointer;
}
.js-pop .content .prize-title {
height: .39rem;
min-width: 1.77rem;
margin: .28rem auto;
line-height: 0.39rem;
color: white;
text-align: left;
text-indent: 1rem;
}
.js-pop .content .prize-content {
color: #a40000;
font-size: .24rem;
margin:0 0.1rem 0 0.49rem;
line-height: 0.4rem;
width: 5.2rem;
}
</style>
</head>
<body>
<button id="bb">显示弹窗</button>
<div class="js-pop js-prize-pop hide" id="popLogin">
<div class="mask"></div>
<div class="content">
<div class="close"></div>
<div class="prize-title">温馨提示</div>
<div class="prize-content" style="margin-top: 1rem">
登录后才能参与活动哦!
<br/>
自动登录跳转中......
</div>
</div>
</div>
<!--引入jquery-->
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.9.1.min.js">
pop.js代码:
//Pop的构造函数
var Pop=function(wrap,option){
var $this=this;
var opt={
closeCall:null
};
$.extend(opt,option);
var mask=wrap.find(".mask");
//特权方法:1、open();2、close();3、setPrize();4、setContent()控制弹窗内显示的内容
this.open=function(){
wrap.show();
mask.show();
};
this.close=function(callbalck){
wrap.hide();
mask.hide();
opt.closeCall&&callbalck();
};
this.setPrize=function(text){
wrap.find(".js-prize").text(text);
};
this.setContent = function (text) {
wrap.find(".js-content").text(text);
};
function events(){
wrap.on("click",".close",function(e){
e.stopPropagation();
$this.close(opt.closeCall);
});
}
events();
};
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
js,弹窗组件,pop
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“js用类封装pop弹窗组件”评论...
更新日志
2025年10月24日
2025年10月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]