通过手机物理返回键实现弹出层的隐藏

 2023-09-13 阅读 14 评论 0

摘要:通过手机物理返回键实现弹出层的隐藏 <template><div class="popup"><h1 @click="popup">返回键隐藏弹出层</h1><div class="pop" :class="{up: flag}">弹出层文本<--点击关闭实现弹出

通过手机物理返回键实现弹出层的隐藏

图片描述

<template><div class="popup"><h1 @click="popup">返回键隐藏弹出层</h1><div class="pop" :class="{up: flag}">弹出层文本<--点击关闭实现弹出层隐藏--><span class="close" @click="close">关闭</span></div></div>
</template><script>/**  总的实现思想即为通过一个开关的true或false值来判断是否需要来添加一条空的历史记录* */export default {data() {return {flag: false}},mounted() {// 当添加历史记录时,通过window下绑定popstate函数进行监听if (window.history && window.history.pushState) {window.addEventListener('popstate', (e) => {this.flag = false})}},methods: {popup() {// 通过class名up的开关flag实现是否通过window.history.pushState添加一条空的历史记录if (!this.flag) {window.history.pushState(null, null, '')}this.flag = true},close() {// 点击关闭时,减少一条历史记录window.history.go(-1)this.flag = false}}}
</script><style scoped lang="stylus">/* 此处用的stylus预编译器 */.popupwidth 100vwheight 100vhoverflow hiddenposition relativeh1text-align centerfont-size 50pxline-height 80px.popwidth 100vwheight 30vhtext-align centerline-height 30vhfont-size 40pxbackground-color lightgrayposition absoluteleft 0bottom -30vhtransition all 800ms.upbottom 0.closewidth 60pxheight 40pxline-height normalposition absoluteright 0top 0font-size 28pxcolor red
</style>

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/50156.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息