index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view
  3. v-if="scrollTop > 400"
  4. class="backTop"
  5. :class="{ 'mescroll-fade-in': isShowToTop }"
  6. @click="toTopClick"
  7. >
  8. <text class="iconfont icondingbu"></text>
  9. </view>
  10. </template>
  11. <script>
  12. import $mAssetsPath from '@/config/assets.config';
  13. export default {
  14. name: 'backTop',
  15. props: {
  16. src: {
  17. type: String,
  18. default: $mAssetsPath.backTop
  19. },
  20. id: {
  21. type: String,
  22. default: ''
  23. },
  24. scrollTop: {
  25. type: Number,
  26. default: 0
  27. },
  28. tab: {
  29. type: Boolean,
  30. default: false
  31. }
  32. },
  33. data() {
  34. return {
  35. isShowToTop: true
  36. };
  37. },
  38. methods: {
  39. toTopClick() {
  40. console.log("返回了")
  41. this.isShowToTop = false; // 回到顶部按钮需要先隐藏,再执行回到顶部,避免闪动
  42. if (this.tab) {
  43. this.$emit('setScrollTop');
  44. } else {
  45. uni.pageScrollTo({
  46. scrollTop: 0,
  47. duration: 300
  48. });
  49. }
  50. }
  51. }
  52. };
  53. </script>
  54. <style lang="scss">
  55. .mescroll-lazy-in,
  56. .mescroll-fade-in {
  57. -webkit-animation: mescrollFadeIn 0.3s linear forwards;
  58. animation: mescrollFadeIn 0.3s linear forwards;
  59. }
  60. .backTop {
  61. z-index: 10;
  62. position: fixed;
  63. right: 40upx;
  64. bottom: 130upx;
  65. /* #ifdef H5 */
  66. bottom: 140upx;
  67. /* #endif */
  68. width: 72upx;
  69. height: 72upx;
  70. border-radius: 50%;
  71. transform: translateZ(0);
  72. -webkit-transform: translateZ(0);
  73. background-color: rgba(0,0,0,.5);
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. .iconfont {
  78. font-size: 54upx;
  79. color: $color-white;
  80. font-weight: 600;
  81. z-index: 100;
  82. }
  83. }
  84. </style>