uni-app waterfall header使用position:sticky 还没有到视图位置header已浮起来

uni-app waterfall header使用position:sticky 还没有到视图位置header已浮起来

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

手机系统:iOS

手机系统版本号:IOS 14

手机厂商:苹果

手机机型:6sp、12 pro

页面类型:nvue

打包方式:云端


示例代码:

<template>  
    <waterfall  
        class="page"  
        column-count="2"  
        :left-gap="5"  
        :right-gap="5"  
        :column-gap="5"  
        column-width="auto"  
        :show-scrollbar="false"  
    >  
        <header>  
            <view class="header">  
                <text class="header-title">header</text>  
            </view>  
        </header>         

        <header style="position: sticky;">  
            <text class="sticky-tag">stickyTags</text>  
        </header>  

        <cell v-for="(item, index) in dataList" :key="item.id">  
            <view>  
                <text>{{item.name}}</text>  
            </view>  
        </cell>  

    </waterfall>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                dataList: []  
            }  
        },  
        created() {  
            for (var i = 0; i < 30; i++) {  
                this.dataList.push({  
                    id: i,  
                    name: i  
                });  
            }  
        }  
    }  
</script>  

<style>  

    .page {  
        flex: 1;  
    }  

    .header {  
        height: 800px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
        background-color: #ff0001;  
    }  

    .header-title {  
        font-size: 30px;  
        font-weight: 700;  
        color: #444;  
    }  

    .sticky-tag {  
        text-align: center;  
        background-color: #007AFF;  
    }  
</style>  

更多关于uni-app waterfall header使用position:sticky 还没有到视图位置header已浮起来的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

2个月时间,来打个卡

更多关于uni-app waterfall header使用position:sticky 还没有到视图位置header已浮起来的实战教程也可以访问 https://www.itying.com/category-93-b0.html


有人能给个回应吗? 是bug的话,另谋他路。

版本更新后,同样有这个问题,求官方快速解决,都是电商平台上面常用到的

在 nvue 的 waterfall 组件中使用 position: sticky 确实存在兼容性问题。waterfall 组件本身基于原生列表渲染,对 CSS sticky 定位支持不完善。

建议改用 waterfall 组件的原生 sticky 功能:

<waterfall
  class="page"
  column-count="2"
  :left-gap="5"
  :right-gap="5"
  :column-gap="5"
  column-width="auto"
  :show-scrollbar="false"
  :sticky-offset-top="0"
>
  <header>
    <view class="header">
      <text class="header-title">header</text>
    </view>
  </header>

  <cell sticky="true">
    <view class="sticky-header">
      <text class="sticky-tag">stickyTags</text>
    </view>
  </cell>

  <cell v-for="(item, index) in dataList" :key="item.id">
    <view>
      <text>{{item.name}}</text>
    </view>
  </cell>
</waterfall>
回到顶部