SlideCard.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view :class="{'SlideCardBox': true, 'show': (dir == 1), 'hide': (dir == 0)}">
  3. <view class="toolBox" @touchstart="touchStartHandle" @touchend="touchEndHandle">
  4. <view @click="clickHandle" class="tool"></view>
  5. </view>
  6. <view class="content" catch:touchmove="true">
  7. <slot></slot>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * 上滑卡片组件
  14. * **/
  15. let startClientY = 0;
  16. let endClientY = 0;
  17. export default {
  18. name:"SlideCard",
  19. data() {
  20. return {
  21. dir: -1 // 0 向下 1 向上
  22. };
  23. },
  24. methods: {
  25. touchStartHandle(evt){
  26. if(evt.changedTouches.length > 0){
  27. startClientY = evt.changedTouches[0].clientY;
  28. }
  29. },
  30. touchEndHandle(evt){
  31. if(evt.changedTouches.length > 0){
  32. endClientY = evt.changedTouches[0].clientY;
  33. }
  34. this.computedDir();
  35. console.log(this.dir)
  36. },
  37. computedDir(){
  38. const diff = endClientY - startClientY
  39. if(diff > 0){ //向下
  40. this.dir = 0;
  41. }else if(diff < 0){ //向上
  42. this.dir = 1;
  43. }
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang="scss">
  49. .SlideCardBox {
  50. position: absolute;
  51. width: 100%;
  52. height: 50vh;
  53. bottom: $tabbar-height;
  54. border-top-left-radius: 10px;
  55. border-top-right-radius: 10px;
  56. background-color: #fff;
  57. z-index: 9;
  58. overflow: hidden;
  59. box-shadow: 0px -8px 16px 0px rgba(150,158,178,0.41);
  60. &:hover {
  61. transition: height 2s;
  62. }
  63. >.toolBox {
  64. padding: 10px 0px;
  65. box-sizing: border-box;
  66. >.tool {
  67. height: 8px;
  68. width: 30%;
  69. margin: auto;
  70. border-radius: 5px;
  71. background-color: #CAD3E4;
  72. }
  73. }
  74. >.content {
  75. padding: 0px 10px;
  76. box-sizing: border-box;
  77. }
  78. &.show {
  79. animation: showAnima 1s forwards;
  80. }
  81. @keyframes showAnima {
  82. 0% {
  83. height: 28px;
  84. }
  85. 100% {
  86. height: 50vh;
  87. }
  88. }
  89. &.hide {
  90. animation: hideAnima 1s forwards;
  91. }
  92. @keyframes hideAnima {
  93. 0% {
  94. height: 50vh;
  95. }
  96. 100% {
  97. height: 28px;
  98. }
  99. }
  100. }
  101. </style>