float-tab.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="float-tab ~column">
  3. <navigator class="tab-img" :style="{top: 3*top + 'px'}" hover-class="none" open-type="switchTab"
  4. url="/pages/index/index">
  5. <image class="tab-icon" src="/static/images/icon_float_home.png" />
  6. </navigator>
  7. <navigator class="tab-img" :style="{top: 2*top + 'px'}" hover-class="none" open-type="navigate"
  8. url="/bundle/pages/chat/chat">
  9. <image class="tab-icon" src="/static/images/icon_float_help.png" />
  10. </navigator>
  11. <navigator class="tab-img" :style="{top: top + 'px'}" hover-class="none" open-type="switchTab"
  12. url="/pages/shop_cart/shop_cart">
  13. <image class="tab-icon" src="/static/images/icon_float_cart.png" />
  14. </navigator>
  15. <image style="z-index: 99" :style="{transform: `rotateZ(${showMore ? 135 : 0}deg)`}" class="tab-img" src="/static/images/icon_float_more.png" @click="onChange" />
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. getRect
  21. } from "@/utils/tools"
  22. export default {
  23. name: "float-tab",
  24. data() {
  25. return {
  26. showMore: false,
  27. top: 0
  28. };
  29. },
  30. mounted() {
  31. getRect(".tab-img", false, this).then(res => {
  32. this.height = res.height
  33. console.log(this.height)
  34. });
  35. },
  36. methods: {
  37. onChange() {
  38. this.showMore = !this.showMore
  39. },
  40. },
  41. watch: {
  42. showMore(val) {
  43. if (val) {
  44. this.top = -this.height
  45. } else {
  46. this.top = 0
  47. }
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="scss">
  53. .float-tab {
  54. position: fixed;
  55. right: 16rpx;
  56. bottom: 200rpx;
  57. width: 96rpx;
  58. height: 96rpx;
  59. z-index: 777;
  60. .tab-img {
  61. width: 100%;
  62. height: 100%;
  63. position: absolute;
  64. transition: all .5s;
  65. .tab-icon {
  66. width: 100%;
  67. height: 100%;
  68. }
  69. }
  70. }
  71. </style>