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
<template>
    <view>
        <scroll-view scroll-y="true" class="scroll" @scroll="scrollChnage">
            <view class="navbar-section" :class="{'navbar-fixed-section': isFixed}">
                <ss-scroll-navbar :tabCurrentIndex="currentIndex" @navbarTap="navbarTapHandler" :scrollChangeIndex="currentI"
                 :navArr="navList"></ss-scroll-navbar>
            </view>
        </scroll-view>
    </view>
</template>
 
<script>
    import ssScrollNavbar from '@/components/navBar/scroll-navbar.vue'
 
    export default {
        props: ['currentI', 'navList'],
        components: {
            ssScrollNavbar
        },
        data() {
            return {
                currentIndex: 0,
                isFixed: false,
                topHeight: 0,
                listData: [],
            }
        },
        onLoad(options) {
            // uni.setNavigationBarTitle({
            //     title: options.title
            // });
            this.calculateTopSectionHeight();
        },
        created() {},
        methods: {
 
            navbarTapHandler(index) {
                this.currentIndex = index;
                this.$emit('currentIndex', index)
            },
            scrollChnage(e) {
                let top = e.detail.scrollTop;
                if (top >= this.topHeight) {
                    this.isFixed = true;
                } else {
                    this.isFixed = false;
                }
            },
            /**
             * 计算头部视图的高度
             */
            calculateTopSectionHeight() {
                var that = this;
                let topView = uni.createSelectorQuery().select(".top-section");
                topView.fields({
                    size: true
                }, data => {
                    that.topHeight = data.height;
                }).exec();
            }
        },
        watch: {
            currentI: function(newVal) {
                this.navbarTapHandler(newVal)
            }
        }
    }
</script>
 
<style lang="scss">
    .scroll {
        // position: absolute;
        // top: 0upx;
        // left: 0upx;
        // bottom: 0upx;
        // right: 0upx;
 
        // .navbar-fixed-section {
        //     position: fixed;
        //     top: 0upx;
        //     left: 0upx;
        //     right: 0upx;
        // }
 
        .top-section {
            height: 350upx;
            background-color: green;
        }
 
        .bottom-section {
            height: 1500upx;
            background-color: yellow;
        }
 
        .footer-section {
            height: 1500upx;
            background-color: blue;
        }
    }
</style>