jc-popUp.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <style>
  2. .jcPopUp{
  3. top:0;
  4. left: 0;
  5. width: 100%;
  6. height: 100%;
  7. position: fixed;
  8. z-index:9999;
  9. }
  10. .jcPopUp-mark{
  11. top: 0;
  12. left: 0;
  13. width: 100%;
  14. height: 100%;
  15. z-index:9997;
  16. position: absolute;
  17. background: rgba(0,0,0,0.5);
  18. }
  19. .jcPopUp-content{
  20. width:100%;
  21. height:100%;
  22. top:0;
  23. left:0;
  24. position: absolute;
  25. z-index:9998;
  26. }
  27. .st{
  28. animation: showTop 0.25s;
  29. }
  30. .sl{
  31. animation: showLeft 0.25s;
  32. }
  33. .sr{
  34. animation: showRight 0.25s;
  35. }
  36. .sb{
  37. animation: shoBottom 0.25s;
  38. }
  39. .ht{
  40. animation: hideTop 0.25s;
  41. }
  42. .hl{
  43. animation: hideLeft 0.25s;
  44. }
  45. .hr{
  46. animation: hideRight 0.25s;
  47. }
  48. .hb{
  49. animation: hideBottom 0.25s;
  50. }
  51. @keyframes showTop{
  52. from {
  53. transform: translateY(-100%);
  54. }
  55. to {
  56. transform: translateY(0);
  57. }
  58. }
  59. @keyframes showLeft{
  60. from {
  61. transform: translateX(-100%);
  62. }
  63. to {
  64. transform: translateY(0);
  65. }
  66. }
  67. @keyframes showRight{
  68. from {
  69. transform: translateX(100%);
  70. }
  71. to {
  72. transform: translateX(0);
  73. }
  74. }
  75. @keyframes showBottom{
  76. from {
  77. transform: translateY(100%);
  78. }
  79. to {
  80. transform: translateY(0);
  81. }
  82. }
  83. @keyframes hideTop{
  84. from {
  85. transform: translateY(0);
  86. }
  87. to {
  88. transform: translateY(-100%);
  89. }
  90. }
  91. @keyframes hideLeft{
  92. from {
  93. transform: translateY(0);
  94. }
  95. to {
  96. transform: translateX(-100%);
  97. }
  98. }
  99. @keyframes hideRight{
  100. from {
  101. transform: translateX(0);
  102. }
  103. to {
  104. transform: translateX(100%);
  105. }
  106. }
  107. @keyframes hideBottom{
  108. from {
  109. transform: translateY(0);
  110. }
  111. to {
  112. transform: translateY(100%);
  113. }
  114. }
  115. </style>
  116. <template name="jc-popUp">
  117. <view class="jcPopUp" v-show="popshow" @click.stop="" v-if="markMove=='false'" @touchmove.stop="">
  118. <view class="jcPopUp-mark"></view>
  119. <view class="jcPopUp-content" @tap="markTap" :class="position=='top'&&!hideanimation?'st':position=='left'&&!hideanimation?'sl':position=='right'&&!hideanimation?'sr':position=='bottom'&&!hideanimation?'sb':position=='top'&&hideanimation?'ht':position=='left'&&hideanimation?'hl':position=='right'&&hideanimation?'hr':position=='bottom'&&hideanimation?'hb':''">
  120. <view style="z-index:1000000;" @tap.stop="">
  121. <slot></slot>
  122. </view>
  123. <icon type="clear" :size="iconSize" color="#FFFFFF" style="position:absolute;" :style="'left:'+iconLeft+'%;top:'+iconTop+'%;'" v-if="closeIcon=='true'" @tap="iconTap"/>
  124. </view>
  125. </view>
  126. <view class="jcPopUp" v-show="popshow" @click.stop="" @tap.stop="" v-else="">
  127. <view class="jcPopUp-mark"></view>
  128. <view class="jcPopUp-content" @tap="markTap" :class="position=='top'&&!hideanimation?'st':position=='left'&&!hideanimation?'sl':position=='right'&&!hideanimation?'sr':position=='bottom'&&!hideanimation?'sb':position=='top'&&hideanimation?'ht':position=='left'&&hideanimation?'hl':position=='right'&&hideanimation?'hr':position=='bottom'&&hideanimation?'hb':''">
  129. <view style="z-index:1000000;" @tap.stop="">
  130. <slot></slot>
  131. </view>
  132. <icon type="clear" :size="iconSize" color="#FFFFFF" style="position:absolute;" :style="'left:'+iconLeft+'%;top:'+iconTop+'%;'" v-if="closeIcon=='true'" @tap="iconTap"/>
  133. </view>
  134. </view>
  135. </template>
  136. <script>
  137. export default {
  138. props:{
  139. position:{ //弹层出现的方位
  140. type:String,
  141. default:""
  142. },
  143. markTapHide:{ //点击蒙层是否关闭弹层
  144. type:String,
  145. default:''
  146. },
  147. markMove:{ // 蒙层是否可以滑动击穿
  148. type:String,
  149. default:'false'
  150. },
  151. closeIcon:{ //是否显示 关闭 图标
  152. type:String,
  153. default:''
  154. },
  155. iconSize:{ //图标大小
  156. type:String,
  157. default:'26'
  158. },
  159. iconTop:{ //图标距离顶部的位置
  160. type:String,
  161. default:'0'
  162. },
  163. iconLeft:{ //图标距离左边的位置
  164. type:String,
  165. default:'0'
  166. }
  167. },
  168. data() {
  169. return {
  170. popshow:false,
  171. hideanimation:false
  172. };
  173. },
  174. methods:{
  175. show(){
  176. this.popshow = true;
  177. },
  178. hide(){
  179. let that = this;
  180. that.hideanimation = true;
  181. if(that.position==null){
  182. that.popshow = false;
  183. }else{
  184. setTimeout(function(){
  185. that.popshow = false;
  186. that.hideanimation = false;
  187. },250)
  188. };
  189. },
  190. markTap(){
  191. let that = this;
  192. if(that.markTapHide != 'true'){
  193. return false
  194. };
  195. that.hideanimation = true;
  196. if(that.position==null){
  197. that.popshow = false;
  198. }else{
  199. setTimeout(function(){
  200. that.popshow = false;
  201. that.hideanimation = false;
  202. },250)
  203. };
  204. },
  205. iconTap(){
  206. let that = this;
  207. if(that.closeIcon != 'true'){
  208. return false
  209. };
  210. that.hideanimation = true;
  211. if(that.position==null){
  212. that.popshow = false;
  213. }else{
  214. setTimeout(function(){
  215. that.popshow = false;
  216. that.hideanimation = false;
  217. },250)
  218. };
  219. }
  220. },
  221. }
  222. </script>