不太完善
<style lang="less" scoped>
.pop{
width: .1875rem;
height: 0rem;
position: absolute;
top: 50%;
left: 50%;
z-index: 999;
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
overflow: hidden;
background: darkgoldenrod;
.rytContent{
font-size: 16px;
color:#333;
box-sizing: border-box;
padding: 0 30px 0 30px;
}
.parent{
position: relative;
}
}
</style>
<template>
<div class="pop" ref="pop">
<div class="" v-if="show">
<div @click="clearWidth">
关闭
</div>
<div class="rytContent parent">
<!-- 具名插槽 -->
<slot name="content"></slot>
</div>
</div>
</div>
</template>
<script>
export default {
props:{
maxWidth:{
type:Number,
default:80.5
},
maxHeight:{
type:Number,
default:50.6
},
loadSpeedWidth:{
type:Number,
default:10
},
loadSpeedHeight:{
type:Number,
default:10
},
},
data() {
return {
width:3,
height:0,
show:false,
}
},
mounted() {
this.loadHeight()
},
methods: {
loadHeight() {
let el = this.$refs.pop;
let athis = this
let time = setInterval(() => {
athis.height++
el.style.height = `${athis.height}%`;
if (athis.height == Math.round(athis.maxHeight)) {
athis.height = athis.maxHeight
el.style.height = `${athis.height}%`;
athis.clearTime(time)
athis.loadWidth()
}
}, athis.loadSpeedHeight);
},
loadWidth(){
let el = this.$refs.pop;
let athis = this
let time = setInterval(() => {
athis.width++
el.style.width = `${athis.width}%`;
if (athis.width == Math.round(athis.maxWidth)) {
athis.width = athis.maxWidth
el.style.width = `${athis.width}%`;
athis.clearTime(time)
athis.show = true
}
}, athis.loadSpeedWidth);
},
clearTime(time){
clearInterval(time)
},
clearHeight() {
let el = this.$refs.pop;
let athis = this
let time = setInterval(() => {
athis.height = athis.height - 1
el.style.height = `${athis.height}%`;
if (Math.round(athis.height) == 0) {
athis.height = 0
el.style.height = `${athis.height}%`;
athis.clearTime(time)
}
}, athis.loadSpeedHeight);
},
clearWidth(){
let el = this.$refs.pop;
let athis = this
athis.show = false
let time = setInterval(() => {
athis.width = athis.width - 1
el.style.width = `${athis.width}%`;
if (Math.round(athis.width) == 1) {
athis.width = 0.1
el.style.width = `${athis.width}%`;
athis.clearTime(time)
athis.clearHeight()
}
}, athis.loadSpeedWidth);
},
},
}
</script>
使用
<pop v-if="isPop" :maxWidth="75" :maxHeight="50">
<span slot="content">
1232132131
</span>
</pop>