01 根据滚动条位置自动展示\隐藏组件;
02 点击返回顶部图标将页面滚动条滚动位置归零
graceToTop : /graceUI/组件目录/graceToTop
| 属性名称 | 类型 | 默认值 | 作用 |
| top | Number | 0 | 页面滚动条滚动距离 |
| color | String | #3688FF | 图标颜色 |
| bottom | String | 80rpx | 组件 bottom 值 |
| background | String | #FFFFFF | 组件背景颜色 |
因 uni-app 底层不支持 uni.pageScrollTo 使用 滚动区域实现返回顶部;
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="demo">
<text>请滚动屏幕体验效果 (:</text>
</view>
<graceToTop :top="top"></graceToTop>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceToTop from "../../graceUI/components/graceToTop.vue";
export default {
data() {
return {
top: 0
}
},
methods:{},
onPageScroll:function(e){
this.top = e.scrollTop;
},
components:{
gracePage, graceToTop
}
}
</script>
<style>
.demo{height:1000px; line-height:2em; padding-top:50rpx; text-align:center; margin-top:60rpx;}
</style> <template>
<gracePage :customHeader="false" flexVal="1">
<!-- 页面主体 -->
<view slot="gBody" ref="gBody" class="grace-flex-v1">
<!-- 因 uni-app 底层不支持 uni.pageScrollTo 使用 滚动区域实现返回顶部 -->
<scroll-view scroll-y="true" :style="{height:mainHeight+'px'}" @scroll="scroll" :scroll-top="top">
<view class="demo" @tap="test">
<text class="demo-text">请滚动屏幕体验效果 (:</text>
</view>
</scroll-view>
<graceToTop :top="top" @totop="totop" background="#F8F8F8"></graceToTop>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceToTop from "../../graceUI/weexComponents/graceToTop.nvue";
const dom = weex.requireModule('dom');
export default {
data() {
return {
top : 0,
mainHeight : 500,
scrollTimer : null
}
},
onReady:function(){
setTimeout(()=>{
// 获取顶部内容高度
var el = this.$refs.gBody;
dom.getComponentRect(el, (res) => {
this.mainHeight = res.size.height;
});
},1000);
},
methods:{
scroll:function(e){
if(this.scrollTimer != null){clearTimeout(this.scrollTimer);}
this.scrollTimer = setTimeout(()=>{
this.top = e.detail.scrollTop;
},200);
},
totop : function () {
this.top = 0;
}
},
components:{
gracePage, graceToTop
}
}
</script>
<style>
.demo{height:2000px; width:700rpx;}
.demo-text{line-height:50rpx; text-align:center; margin-top:60rpx; font-size:26rpx;}
</style> .wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="demo">
<text>请滚动屏幕体验效果 (:</text>
</view>
<graceToTop top="{{top}}"></graceToTop>
</view>
</gracePage>.js
Page({
data: {
top:0
},
onPageScroll: function (e) {
this.setData({top : e.scrollTop});
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceToTop": "../../graceUI/components/graceToTop"
}
}.wxss
.demo{height:1000px; line-height:2em; padding-top:50rpx; text-align:center; margin-top:60rpx;}