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