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. this.isShowToTop = false; // 回到顶部按钮需要先隐藏,再执行回到顶部,避免闪动
  41. if (this.tab) {
  42. this.$emit('setScrollTop');
  43. } else {
  44. uni.pageScrollTo({
  45. scrollTop: 0,
  46. duration: 300
  47. });
  48. }
  49. }
  50. }
  51. };
  52. </script>
  53. <style lang="scss">
  54. .mescroll-lazy-in,
  55. .mescroll-fade-in {
  56. -webkit-animation: mescrollFadeIn 0.3s linear forwards;
  57. animation: mescrollFadeIn 0.3s linear forwards;
  58. }
  59. .backTop {
  60. z-index: 10;
  61. position: fixed;
  62. right: 40upx;
  63. bottom: 240upx;
  64. /* #ifdef H5 */
  65. margin-bottom: env(safe-area-inset-bottom);
  66. /* #endif */
  67. width: 72upx;
  68. height: 72upx;
  69. border-radius: 50%;
  70. transform: translateZ(0);
  71. -webkit-transform: translateZ(0);
  72. background-color: #000;
  73. display: flex;
  74. justify-content: center;
  75. opacity: 0.5;
  76. align-items: center;
  77. .iconfont {
  78. font-size: 54upx;
  79. color: $color-white;
  80. opacity: 1;
  81. z-index: 100;
  82. }
  83. }
  84. </style>