index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <view class="u-no-demo-here">滚动页面即可在右下角看到返回顶部的按钮</view>
  7. </view>
  8. <u-back-top :scrollTop="scrollTop" :mode="mode"
  9. :bottom="bottom" :right="right" :top="top" :icon="icon" :custom-style="customStyle"
  10. :icon-style="iconStyle" :tips="tips"
  11. >
  12. </u-back-top>
  13. </view>
  14. <view class="u-config-wrap">
  15. <view class="u-config-title u-border-bottom">
  16. 参数配置
  17. </view>
  18. <view class="u-config-item">
  19. <view class="u-item-title">模式</view>
  20. <u-subsection :list="['圆形', '方形']" @change="modeChange"></u-subsection>
  21. </view>
  22. <view class="u-config-item">
  23. <view class="u-item-title">组件位置</view>
  24. <u-subsection :list="['默认', '自定义']" @change="positionChange"></u-subsection>
  25. </view>
  26. <view class="u-config-item">
  27. <view class="u-item-title">显示组件的滚动条距离</view>
  28. <u-subsection current="1" :list="['200', '400', '600']" @change="scrollTopChange"></u-subsection>
  29. </view>
  30. <view class="u-config-item">
  31. <view class="u-item-title">自定义样式</view>
  32. <u-subsection current="1" :list="['是', '否']" @change="styleChange"></u-subsection>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. scrollTop: 0,
  42. mode: 'circle',
  43. bottom: 200,
  44. right: 40,
  45. top: 400,
  46. icon: 'arrow-upward',
  47. iconStyle: {
  48. color: '#909399',
  49. fontSize: '38rpx'
  50. },
  51. customStyle: {},
  52. tips: ''
  53. }
  54. },
  55. methods: {
  56. modeChange(index) {
  57. this.mode = !index ? 'circle' : 'square';
  58. },
  59. positionChange(index) {
  60. if(index == 0) {
  61. this.bottom = 200;
  62. this.right = 40;
  63. } else {
  64. this.bottom = 400;
  65. this.right = 80;
  66. }
  67. },
  68. scrollTopChange(index) {
  69. this.top = [200, 400, 600][index];
  70. },
  71. styleChange(index) {
  72. if(index == 0) {
  73. this.icon = 'arrow-up';
  74. this.iconStyle = {
  75. color: '#2979ff',
  76. fontSize: '34rpx'
  77. };
  78. this.customStyle = {
  79. backgroundColor: '#a0cfff',
  80. color: '#2979ff'
  81. };
  82. this.tips = '顶部';
  83. } else {
  84. this.icon = 'arrow-upward';
  85. this.iconStyle = {
  86. color: '#909399',
  87. fontSize: '38rpx'
  88. };
  89. this.customStyle = {};
  90. this.tips = '';
  91. }
  92. }
  93. },
  94. onPageScroll(e) {
  95. this.scrollTop = e.scrollTop;
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .u-demo {
  101. height: 200vh;
  102. }
  103. </style>