use-totop.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="use-totop fixed-top animated" :class="visible ? 'fade-in' : 'dn'" :style="{ bottom: bottom + 'rpx', right: right + 'rpx' }" @tap.stop="totop">
  3. <text class="iconfont iconzhiding"></text>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. top: {
  10. type: Number,
  11. default: 100
  12. },
  13. right: {
  14. type: String,
  15. default: '30'
  16. },
  17. bottom: {
  18. type: String,
  19. default: '120'
  20. },
  21. duration:{
  22. type: Number,
  23. default: 120
  24. },
  25. scrollTop: {
  26. type: Number,
  27. default: 0
  28. }
  29. },
  30. watch: {
  31. scrollTop(nv, ov) {
  32. this.s_top = nv;
  33. this.change();
  34. }
  35. },
  36. data() {
  37. return {
  38. s_top: 0,
  39. visible: false
  40. };
  41. },
  42. methods: {
  43. totop: function() {
  44. uni.pageScrollTo({
  45. scrollTop: 0,
  46. duration: this.duration
  47. })
  48. this.$emit('to', {
  49. type: 'to',
  50. scrollTop: this.s_top
  51. });
  52. },
  53. change(scrollTop) {
  54. this.s_top = scrollTop;
  55. if(this.s_top > this.top) {
  56. if(!this.visible) this.visible = true;
  57. } else {
  58. if(this.visible) this.visible = false;
  59. }
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. .use-totop {}
  66. </style>