fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!--
/**
* @description 模态框组件
* @author shm
*/
-->
<template>
  <div class="moval-box" :class="visable ? 'modal-box-open' : 'modal-box-close'">
    <div class="modal-cover" @click="clickCover"></div>
    <div class="modal-content" :class="visable ? 'modal-content-open' : 'modal-content-close'">
      <div class="title pos-relative" v-if="title">{{ title }}
        <img src="~@/assets/images/goodsDetail/modal_close.png" class="common-right-icon close_icon"
             @click="clickCover" />
      </div>
      <slot name="modal-content"></slot>
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'NewModal',
  props: {
    visable: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    }
  },
  mounted () {
    const { body } = document
    const scrollTop = document.body.scrollTop || document.documentElement.scrollTop
    body.style.position = 'fixed'
    body.style.width = '100%'
    body.style.top = `-${scrollTop}px`
  },
  beforeDestroy () {
    const { body } = document
    const { top } = body.style
    body.style.position = ''
    body.style.width = ''
    body.style.top = ''
    document.body.scrollTop = -parseInt(top, 10)
    document.documentElement.scrollTop = -parseInt(top, 10)
  },
  methods: {
    clickCover () {
      this.$emit('close-modal')
    }
  }
}
</script>
 
<style lang="scss" scoped>
.modal-box {
  max-height: 900px;
}
.modal-box-open {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  animation: fade-in 0.5s;
 
  // transition: all 0.4s cubic-bezier(0.25, 1, 0.25, 1);
  .modal-cover {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
  }
}
 
/deep/.title {
  line-height: 80px;
  text-align: center;
  font-weight: 600;
  font-size: 32px;
  .close_icon {
    position: absolute;
    right: 0;
    top: 20px;
  }
}
 
.modal-box-close {
  height: 0;
  padding: 0;
}
 
.modal-content {
  width: 100%;
  background: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  padding: 20px;
  box-sizing: border-box;
}
.modal-content-open {
  border-radius: 20px 20px 0 0;
  // transition: bottom 1.5s ease-in;
  // height: 30%;
  // transform: scaleY(1);
  // transition: all 0.5s
  animation: fade-in 0.5s;
  // transition: height 0.5s;
}
 
.modal-content-close {
  height: 0;
  animation: fade-out 0.5s;
  padding: 0;
  // transition: all 1.5s ease-out;
  // transition: height 0.5s;
}
 
@keyframes fade-out {
  0% {
    opacity: 1;
    -webkit-transform: translateY(1);
    transform: translateY(1);
  }
 
  100% {
    opacity: 0;
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}
 
@keyframes fade-in {
  0% {
    opacity: 0;
    -webkit-transform: translateY(1);
    transform: translateY(1);
  }
 
  100% {
    opacity: 1;
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}
</style>