关于前端自动弹窗页面

这篇博客展示了一个前端自动弹窗页面的实现,使用了layer插件。当用户点击‘点击弹出’按钮时,会显示一个包含预约成功信息的弹窗,包括预约号和后续操作提示。此外,提供了layer插件的链接供进一步了解。
摘要由CSDN通过智能技术生成
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>您已成功免费预约</title>
<style>
*{ margin:0px; padding:0px;}
/*弹出css开始*/
.layer_box { display:none; width:500px; height:500px; background:#FFFFFF; margin:0px auto; text-align:center; font-family: Microsoft YaHei;}
.layer_box h2,.layer_box h3,.layer_box h4 {font-size: 100%; font-weight: 500;}
.layer_icon { padding-top:56px; padding-bottom:38px;}
.layer_icon span{ display:block; background:url(layer/layer_icon.png) no-repeat center center; width:88px; height:88px; margin:0px auto;}
.layer_box h2,.layer_box h3 { font-size:26px; color:#171717;}
.layer_box h3 span { color:#0f95da;}
.layer_box h4 { font-size:24px; padding-top:44px;}
.layer_box h4 cite { color:#e9130e;font-style:normal;}
.layer_info { padding-top:60px; color:#7a7a7a;}
.layer_info a { color:#e9130e;}
/*弹出css结束*/
</style>
</head>

<body><br>
<br>
<div id=
你可以使用 `setInterval` 函数来创建定器,然后使用 `clearInterval` 函数来清除定器。为了同定义三个定器,你可以在 `setup` 函数中使用 `ref` 来定义三个变量来保存定器的 ID,然后在对应的间间隔内执行相应的操作。 下面是一个示例代码,其中包含了三个定器,分别为 10 秒、20 秒和 30 秒,以及一个用于控制弹窗显示的变量 `showPopup`: ```html <template> <div> <button @click="showPopup = true">Show Popup</button> <Popup :show="showPopup" @cancel="stopTimer" /> <div v-if="showPopup"> <h2>Popup</h2> <button @click="hidePopup">Cancel</button> </div> </div> </template> <script setup> import { ref, onMounted, onUnmounted } from 'vue' import Popup from './Popup.vue' const timer1 = ref(null) const timer2 = ref(null) const timer3 = ref(null) const showPopup = ref(false) const startTimer = (id) => { if (id === 1) { timer1.value = setInterval(() => { console.log('Timer 1') }, 10000) } else if (id === 2) { timer2.value = setInterval(() => { console.log('Timer 2') }, 20000) } else if (id === 3) { timer3.value = setInterval(() => { console.log('Timer 3') }, 30000) } } const stopTimer = () => { clearInterval(timer1.value) clearInterval(timer2.value) clearInterval(timer3.value) } const showPopup = () => { showPopup.value = true } const hidePopup = () => { showPopup.value = false } onMounted(() => { // 在页面刷新或离开停止定器 window.addEventListener('beforeunload', stopTimer) }) onUnmounted(() => { window.removeEventListener('beforeunload', stopTimer) }) </script> <script> import Popup from './Popup.vue' export default { components: { Popup }, setup() { // ... } } </script> ``` 在上面的代码中,我们使用了 `onMounted` 和 `onUnmounted` 钩子函数来在页面加载和卸载分别进行一些操作。在页面加载,我们添加了一个监听器来在页面刷新或离开停止定器。 当点击开始按钮,我们使用 `startTimer` 函数来启动对应的定器,当点击停止按钮,我们使用 `stopTimer` 函数来停止所有定器。当点击弹窗上的取消按钮,我们使用 `hidePopup` 函数来隐藏弹窗。 请注意,上面的代码仅为示例,你需要根据具体需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值