graceShade.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <view class="grace-shade"
  3. :style="{zIndex:zIndex, background:background, height:shadeShow?'100%':'0px'}"
  4. @tap.stop="closeShade" @touchmove.stop.prevent="">
  5. <view :class="[showInReal ? 'grace-shade-in' : 'grace-shade-out']"><slot></slot></view>
  6. </view>
  7. </template>
  8. <script>
  9. export default{
  10. props:{
  11. background : {type:String, default:"rgba(0, 0, 0, 0.1)"},
  12. zIndex : {type:Number, default:1},
  13. show : {type:Boolean, default:false}
  14. },
  15. data() {
  16. return {
  17. shadeShow : false,
  18. showInReal : false
  19. }
  20. },
  21. created:function(){
  22. if(this.show){ this.showIt(); }else{ this.hideIt();}
  23. },
  24. watch:{
  25. show:function(val){
  26. if(val){ this.showIt(); }else{ this.hideIt(); }
  27. }
  28. },
  29. methods:{
  30. closeShade : function(){
  31. this.$emit('closeShade');
  32. },
  33. showIt : function(){
  34. this.shadeShow = true;
  35. setTimeout(()=>{
  36. this.showInReal = true;
  37. }, 50);
  38. },
  39. hideIt : function(){
  40. this.showInReal = false;
  41. setTimeout(()=>{
  42. this.shadeShow = false;
  43. }, 150);
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped>
  49. .grace-shade{position:fixed; width:100%; height:100%; left:0; top:0; bottom:0; overflow:hidden; display:flex; justify-content:center; align-items:center;}
  50. .grace-shade-in{animation:grace-shade-in-a 150ms ease-in forwards;}
  51. @keyframes grace-shade-in-a{0%{transform: scale(0.1); opacity:0;} 100%{transform: scale(1); opacity:1;}}
  52. .grace-shade-out{animation:grace-shade-out-a 150ms ease-out forwards;}
  53. @keyframes grace-shade-out-a{0%{transform: scale(1); opacity:1;} 100%{transform: scale(0.1); opacity:0;}}
  54. </style>