Skip to content

Sticky 粘性布局

介绍

效果同 css 中的 position: sticky,对低端浏览器可使用其做兼容。

只支持吸顶效果,也可以使用官方推荐 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/component-plus/sticky.html

基础用法

html
<template>
    <div class="demo">
       <view class="container">
        <mot-cell title="滚动页面,即可看到下方的按钮会吸顶" />
       </view>
       <mot-sticky>
         <mot-button type="primary" style="margin-left: 50px">
          吸顶按钮
         </mot-button>
       </mot-sticky>
    </div>
</template>
<style lang="scss">
    .demo {
        height: 1500px !important;
    }
</style>

吸顶距离

html
<template>
    <div class="demo">
        <mot-sticky offset-top="120">
            <mot-button type="primary">吸顶距离120px</mot-button>
        </mot-sticky>
    </div>
</template>
<style lang="scss">
  .demo {
      height: 1500px !important;
  }
</style>

API

Props

参数说明类型默认值
offset-top吸顶距离number0
z-index吸附时的层级number2000
customNavHeight导航栏高度,自定义导航栏时,需要传入此值number0
disabled是否禁用吸顶功能booleanfalse
bg-color组件背景颜色string#ffffff
index自定义标识,用于区分是哪一个组件number

MIT Licensed