<template>
<div class="xn-container">
<button class="error" @click="showVuePopup(true)">点我</button>
<div class="vue-popup">
<div class="mask" v-show="show" @click="showVuePopup(false)"></div>
<transition name="slide">
<div class="popup-content" v-show="show" >
<p>点击阴影区域可以关闭</p>
<p @click="showVuePopup(false)">点击我也可以关闭哟</p>
</div>
</transition>
</div>
</div>
</template>
<script>
export default {
name: 'Test',
data () {
return {
show: false
}
},
methods: {
showVuePopup (flag) {
this.show = flag
}
}
}
</script>
<style lang="stylus" scoped>
.xn-container {
height: 100%;
}
button {
display: block;
width: 300px;
height: 44px;
margin: 20px auto;
border-radius: 4px;
background-color: #3884ff;
color: #fff;
}
.error{
touch-action: none;
}
// 内容区
.vue-popup {
.popup-content {
touch-action: none;
position: fixed;
border-radius: 1rem 1rem 0 0
height: 400px;
bottom: 0;
left: 0;
width: 100%;
background-color: #fff;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
p {
line-height: 30px;
text-align: center;
}
}
}
// 阴影区
.mask {
touch-action: none;
position: fixed;
width: 100%;
right:0;
left: 0;
top: 0;
bottom: 0;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
transition: all 0.2s ease-in;
}
.slide-enter-active {
animation-name: slideInUp;
animation-duration: 0.2s;
animation-fill-mode: both;
}
.slide-leave-active {
animation-name: slideOutDown;
animation-duration: 0.2s;
animation-fill-mode: both;
}
@keyframes slideInUp {
0% {
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
transform: translateZ(0);
}
}
@keyframes slideOutDown {
0% {
transform: translateZ(0);
}
to {
visibility: hidden;
transform: translate3d(0, 100%, 0);
}
}
</style>
效果图: