JS 原生控制弹出框注册模块

下文只是一个简单的div+css+js 的弹出demo,但是比较实用也不复杂,扩展性很高;一些绚丽的效果都可以基于这个原型相对来说非常实用。

具体扩展我这不多说了。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>弹出提示</title>
<style>
* {margin:0;padding:0;font-size:12px;}
html,body {height:100%;width:100%;}
#content {background:#f8f8f8;padding:30px;height:100%;}
#content a {font-size:30px;color:#369;font-weight:700;}
#alert {border:1px solid #369;width:300px;height:150px;background:#e2ecf5;z-index:1000;position:absolute;display:none;}
#alert h4 {height:20px;background:#369;color:#fff;padding:5px 0 0 5px;}
#alert h4 span {float:left;}
#alert h4 span#close {margin-left:210px;font-weight:500;cursor:pointer;}
#alert p {padding:12px 0 0 30px;}
#alert p input {width:120px;margin-left:20px;}
#alert p input.myinp {border:1px solid #ccc;height:16px;}
#alert p input.sub {width:60px;margin-left:30px;}
</style>

</head>

<body>
<div id="content">
<a href="#">HELP</a>
</div>
<div id="alert">
<h4><span>HELP-01</span><span id="close">关闭</span></h4>
<p><label>      新闻滚动,根据时间,最新新闻标题滚动,点击标题弹出页面,显示全部内容,点击右上角 〉〉更多   弹出页面,显示更多新闻标题
</label></p>
<p><label>&nbsp;&nbsp;</label></p>
<p></p>
</div>
<script type="text/javascript">
var myAlert = document.getElementById("alert");
var reg = document.getElementById("content").getElementsByTagName("a")[0];
var mClose = document.getElementById("close");
reg.onclick = function()
{
myAlert.style.display = "block";
myAlert.style.position = "absolute";
myAlert.style.top = "50%";
myAlert.style.left = "50%";
myAlert.style.marginTop = "-75px";
myAlert.style.marginLeft = "-150px";

mybg = document.createElement("div");
mybg.setAttribute("id","mybg");
mybg.style.background = "#000";
mybg.style.width = "100%";
mybg.style.height = "100%";
mybg.style.position = "absolute";
mybg.style.top = "0";
mybg.style.left = "0";
mybg.style.zIndex = "500";
mybg.style.opacity = "0.3";
mybg.style.filter = "Alpha(opacity=30)";
document.body.appendChild(mybg);

document.body.style.overflow = "hidden";
}

mClose.onclick = function()
{
myAlert.style.display = "none";
mybg.style.display = "none";
}
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3 是一款流行的 JavaScript 架,用于构建用户界面和单页面应用程序。手写原生弹出可以通过 Vue 3 的组件来实现,以下是一个简单的示例: 1. 新建一个名为 "MyAlert" 的 Vue 组件,该组件包含一个 "message" 属性和一个方法 "closeAlert"。 ``` <template> <div class="my-alert" v-show="visible"> <div class="my-alert-mask" @click="closeAlert"></div> <div class="my-alert-content"> <p>{{ message }}</p> <button @click="closeAlert">确定</button> </div> </div> </template> <script> export default { props: { message: { type: String, default: "", }, }, data() { return { visible: true, }; }, methods: { closeAlert() { this.visible = false; }, }, }; </script> <style scoped> .my-alert { position: fixed; top: 0; left: 0; right: 0; bottom: 0; } .my-alert-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); } .my-alert-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; } </style> ``` 2. 在需要弹出的地方使用该组件,并传递要显示的消息。 ``` <template> <div> <button @click="showAlert">弹出</button> <my-alert :message="alertMsg" v-if="isShowAlert" @closeAlert="isShowAlert=false"></my-alert> </div> </template> <script> import MyAlert from "./MyAlert.vue"; export default { components: { MyAlert, }, data() { return { isShowAlert: false, alertMsg: "", }; }, methods: { showAlert() { this.isShowAlert = true; this.alertMsg = "这是一个弹出"; }, }, }; </script> ``` 这样就可以实现一个简单的手写原生弹出。相比于使用浏览器的原生弹出,自定义的弹出更加灵活,并且可以根据需求进行自由扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值