uniapp 滚动到指定位置后div跟随滚动

uniapp yekong 1594℃

html


        <div class="daohang" :class="{ flex: topx < top }">
            <v-tabs
                bgColor="none"
                :lineScale="0.4"
                height="80rpx"
                fontSize="28rpx"
                :tabs="tabs"
                v-model="current"
                :scroll="false"
                line-color="#ff679a"
                active-color="#ff679a"
                style="width: 100%;"
                lineHeight="6rpx"
                @change="changeTab"
            ></v-tabs>
        </div>

js


    onReady() {
        let view = uni
            .createSelectorQuery()
            .in(this)
            .select('.daohang');
        view.fields(
            {
                size: true,
                scrollOffset: true
            },
            data => {
                console.log('得到节点信息' + JSON.stringify(data));
                console.log('节点的宽为' + data.width);
            }
        ).exec();
        view.boundingClientRect(data => {
            this.topx = data.top;
        }).exec();
    },

css


.flex {
    position: fixed;
    width: 750rpx;
    top: 0rpx;
    padding-top: calc(var(--status-bar-height) + 70rpx);
    z-index: 1111;
}
喜欢 (6)