uniapp实现今日头条中个人中心的上拉吸顶并头部标题栏显示头像功能

<template>
    <view class="cont">
        <uni-nav-bar :title="''" left-icon="left"
            style="position: sticky;top: 0;z-index: 99999;padding-top: var(--status-bar-height);"
            :background-color="'#fff'">
            <image v-if="showComponent" src="../static/vip.png" style="width: 30rpx;height: 30rpx;" mode=""></image>
            <block slot="right">
                <view class="city">
                    搜索
                </view>
            </block>
        </uni-nav-bar>
        <scroll-view style="width:100%;height: 100vh;" scroll-y @scroll="scrollTopFun" @scrolltolower="scrolltolower">
            <view class="" style="height: 120rpx;background-color: forestgreen;">

            </view>
            <v-tabs :class="showComponent ? 'topnav' : ''" id="tab-bar" style="width: 100%;" v-model="current"
                :tabs="tabs" ref="tabTitle" bgColor="#f6f6f6" color="#000" activeColor="#000" bold lineColor="#8157F4"
                @change="changeTab">
            </v-tabs>
            <view id="list" class="" v-for="item in dataList" style="height: 200rpx;">
                { {item.title}}
            </view>
        </scroll-view>
    </view>
</template>

<script>
    export default {
        components: {
        },
        data() {
            return {
                scrollViewomponents: '#list', // 内容 容器 计算距离顶部距离使用
                showComponent: false, // 是否显示
                tabs: ['关注', '推荐', '问答'],
                current: 1,
                dataList: [{
                        img: '../../static/logo.png',
                        title: '幻灯1',
                        info: '简介',
                        another: '额外',
                        id: 1
                    },
                    {
                        img: '../../static/logo.png',
                        title: 

  • 26
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
uniapp实现效果可以通过以下步骤: 1. 在需要实现效果的组件或页面,添加一个固定位置的容器,比如`<view>`。 2. 给该容器设置一个固定的高度,并设置其`position`属性为`fixed`,使其固定在页面部。 3. 监听页面的滚动事件,在页面滚动到一定位置时,将容器的`position`属性改为`relative`,使其跟随页面滚动。 下面是一个简单的示例代码: ```html <template> <view> <!-- 固定在页面部的容器 --> <view class="sticky-container" :style="{height: containerHeight + 'px', position: sticky ? 'fixed' : 'relative'}"> <!-- 容器的内容 --> <view class="content">我是的内容</view> </view> <!-- 页面内容 --> <view class="page-content"></view> </view> </template> <script> export default { data() { return { sticky: false, // 是否启用效果 containerHeight: 50 // 容器的高度 }; }, mounted() { // 监听页面滚动事件 uni.pageScrollTo({ scrollTop: 0, // 滚动到页面部 duration: 0 // 立即滚动,不需要动画效果 }); uni.onPageScroll((e) => { // 当页面滚动到一定位置时启用效果 if (e.scrollTop >= 100) { this.sticky = true; } else { this.sticky = false; } }); } }; </script> <style> .sticky-container { background-color: #f2f2f2; z-index: 100; } .content { text-align: center; line-height: 50px; } .page-content { height: 1000px; } </style> ``` 在上述示例代码,我们通过监听`uni.onPageScroll`事件来实现页面滚动的监控,并通过改变`sticky`数据来改变容器的`position`属性。当页面滚动到一定位置时,容器会固定在页面部,实现效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值