toTop.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!-- 回到顶部的按钮 -->
  2. <template>
  3. <image
  4. class="mescroll-totop"
  5. :class="[value ? 'mescroll-totop-in' : 'mescroll-totop-out']"
  6. :src="$util.img('upload/uniapp/mescroll-totop.png')"
  7. mode="widthFix"
  8. @click="toTopClick"
  9. />
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. value: true
  16. };
  17. },
  18. methods: {
  19. toTopClick() {
  20. this.$emit('toTop'); // 派发点击事件
  21. }
  22. }
  23. };
  24. </script>
  25. <style>
  26. /* 回到顶部的按钮 */
  27. .mescroll-totop {
  28. z-index: 99;
  29. position: fixed !important; /* 加上important避免编译到H5,在多mescroll中定位失效 */
  30. right: 46rpx !important;
  31. bottom: 272rpx !important;
  32. width: 72rpx;
  33. height: 72rpx;
  34. border-radius: 50%;
  35. opacity: 0;
  36. transition: opacity 0.5s; /* 过渡 */
  37. margin-bottom: var(--window-bottom); /* css变量 */
  38. }
  39. /* 适配 iPhoneX */
  40. .mescroll-safe-bottom {
  41. margin-bottom: calc(var(--window-bottom) + constant(safe-area-inset-bottom)); /* window-bottom + 适配 iPhoneX */
  42. margin-bottom: calc(var(--window-bottom) + env(safe-area-inset-bottom));
  43. }
  44. /* 显示 -- 淡入 */
  45. .mescroll-totop-in {
  46. opacity: 1;
  47. }
  48. /* 隐藏 -- 淡出且不接收事件*/
  49. .mescroll-totop-out {
  50. opacity: 0;
  51. pointer-events: none;
  52. }
  53. </style>