gui-totop.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view
  3. class="gui-totop gui-fade-in gui-bg-white gui-dark-bg-level-3"
  4. hover-class="gui-tap"
  5. v-if="show"
  6. @tap="totop"
  7. :style="{
  8. bottom:bottom,right:right,
  9. zIndex:zIndex,
  10. borderRadius:borderRadius
  11. }">
  12. <text
  13. class="gui-icons gui-block gui-totop-text gui-primary-color gui-dark-text-level-2"
  14. :style="{
  15. fontSize:fontSize
  16. }">&#xe637;</text>
  17. </view>
  18. </template>
  19. <script>
  20. export default{
  21. name : "gui-totop",
  22. props : {
  23. top : { type : Number, default : 0 },
  24. bottom : { type : String, default : "80rpx" },
  25. right : { type : String, default : "30rpx" },
  26. borderRadius : { type : String, default : "6rpx" },
  27. zIndex : { type : Number, default : 9},
  28. fontSize : { type : String, default : "44rpx" }
  29. },
  30. data() {
  31. return {
  32. show : false,
  33. timer : null
  34. }
  35. },
  36. watch:{
  37. top : function(topVal){
  38. if(this.timer != null){clearTimeout(this.timer);}
  39. this.timer = setTimeout(()=>{
  40. this.show = topVal > 100 ? true : false;
  41. }, 80);
  42. }
  43. },
  44. methods:{
  45. totop : function(){
  46. // #ifndef APP-NVUE
  47. uni.pageScrollTo({
  48. scrollTop:0,
  49. duration:100
  50. })
  51. // #endif
  52. this.$emit('totop');
  53. }
  54. },
  55. // #ifdef APP-NVUE
  56. emits : ['totop']
  57. // #endif
  58. }
  59. </script>
  60. <style scoped>
  61. .gui-totop{width:80rpx; height:80rpx; position:fixed;}
  62. .gui-totop-text{width:80rpx; height:80rpx; line-height:80rpx; font-size:38rpx; text-align:center;}
  63. </style>