index.js 1.71 KB
import wx from '../../utils/wx';

let systemInfo = wx.getSystemInfoSync();

Component({
    properties: {
        isTop: { // 是否展示返回顶部按钮
            type: Boolean,
            value: false
        },
        isShare: { // 是否显示分享
            type: Boolean,
            value: false
        }
    },
    data: {
        isTopShow: true,
        indicatorAnimation: {},
        height: 0,
        scrollTop: 0
    },
    ready: function() {
        this.setData({height: systemInfo.windowHeight});
    },
    methods: {
        tapShare: function() {
            this.triggerEvent('tapShare', {});
        },
        tapComponentsMore: function() {
            this.triggerEvent('tapLoadMore', {});
        },
        backToTop: function() {
            this.setData({scrollTop: 0});
        },
        onScroll: function(e) {
            if (this.data.isTop) { // 返回顶部按钮显示 不显示控制
                let { scrollTop } = e.detail || {};
                let isTopShow = scrollTop > systemInfo.windowHeight * 2 ? true : false;

                if (isTopShow !== this.data.isTopShow) {
                    let animtionIndicator = wx.createAnimation({
                        duration: 300,
                        timingFunction: 'linear',
                    });

                    if (isTopShow) {
                        animtionIndicator.opacity(1).step();
                    } else {
                        animtionIndicator.opacity(0).step();
                    }

                    this.setData({
                        indicatorAnimation: animtionIndicator.export(),
                        isTopShow: isTopShow
                    });
                }
            }
        }
    }
});