graceToTop.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view class="grace-totop" v-if="show" @tap="totop" :style="{bottom:bottom, background:background}">
  3. <text class="totopfont icon-top" :style="{color:color}"></text>
  4. </view>
  5. </template>
  6. <script>
  7. export default{
  8. props:{
  9. top : {
  10. type : Number,
  11. default : 0
  12. },
  13. color : {
  14. type : String,
  15. default : "#3688FF"
  16. },
  17. bottom : {
  18. type : String,
  19. default : "80rpx"
  20. },
  21. background:{
  22. type : String,
  23. default : "#FFFFFF"
  24. }
  25. },
  26. data() {
  27. return {
  28. show : false,
  29. timer : null
  30. }
  31. },
  32. watch:{
  33. top : function(topVal){
  34. if(this.timer != null){clearTimeout(this.timer);}
  35. this.timer = setTimeout(function(){
  36. if(topVal > 100){
  37. this.show = true;
  38. }else{
  39. this.show = false;
  40. }
  41. }.bind(this), 80);
  42. }
  43. },
  44. methods:{
  45. totop : function(){
  46. uni.pageScrollTo({
  47. scrollTop: 0,
  48. duration: 0
  49. });
  50. }
  51. }
  52. }
  53. </script>
  54. <style scoped>
  55. .totopfont {
  56. font-family:"grace-iconfont";
  57. font-style: normal;
  58. }
  59. .icon-top:before {content:"\e637"; font-size:22px;}
  60. .grace-totop{width:40px; height:40px; line-height:40px; background:#FFFFFF; color:#3688FF; position:fixed; bottom:80px; z-index:9999; right:15px; border-radius:5px; box-shadow:0px 0px 2px #EEE; text-align:center;}
  61. </style>