Sticky 吸顶容器

概述

用于将标题栏在滚动时固定到页面顶部。

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-sticky": "../../dist/sticky/index",
  3. "i-sticky-item": "../../dist/sticky-item/index"
  4. }

示例

  1. <view class="i-sticky-demo-des">
  2. 注: 1.由于组件内部不能使用onPageScroll,导致不能监听scrollTop值只能通过用户用props传递。
  3. </view>
  4. <view class="i-sticky-demo-des">
  5. 2.在微信开发客户端显示的时候会有bug。不停计算scrollTop值不能同步
  6. </view>
  7. <view class="i-sticky-demo">
  8. <i-sticky scrollTop="{{scrollTop}}">
  9. <i-sticky-item i-class="i-sticky-demo-title">
  10. <view slot="title">
  11. 逻辑层
  12. </view>
  13. <view slot="content">
  14. <view class="i-sticky-demo-item">注册程序</view>
  15. <view class="i-sticky-demo-item">场景值</view>
  16. <view class="i-sticky-demo-item">注册页面</view>
  17. <view class="i-sticky-demo-item">路由</view>
  18. <view class="i-sticky-demo-item">模块化</view>
  19. <view class="i-sticky-demo-item">API</view>
  20. </view>
  21. </i-sticky-item>
  22. <i-sticky-item i-class="i-sticky-demo-title">
  23. <view slot="title">
  24. 视图层
  25. </view>
  26. <view slot="content">
  27. <view class="i-sticky-demo-item">注册程序</view>
  28. <view class="i-sticky-demo-item">场景值</view>
  29. <view class="i-sticky-demo-item">注册页面</view>
  30. <view class="i-sticky-demo-item">路由</view>
  31. <view class="i-sticky-demo-item">模块化</view>
  32. <view class="i-sticky-demo-item">API</view>
  33. </view>
  34. </i-sticky-item>
  35. <i-sticky-item i-class="i-sticky-demo-title">
  36. <view slot="title">
  37. 自定义组件
  38. </view>
  39. <view slot="content">
  40. <view class="i-sticky-demo-item">注册程序</view>
  41. <view class="i-sticky-demo-item">场景值</view>
  42. <view class="i-sticky-demo-item">注册页面</view>
  43. <view class="i-sticky-demo-item">路由</view>
  44. <view class="i-sticky-demo-item">模块化</view>
  45. <view class="i-sticky-demo-item">API</view>
  46. <view class="i-sticky-demo-item">注册程序</view>
  47. <view class="i-sticky-demo-item">场景值</view>
  48. <view class="i-sticky-demo-item">注册页面</view>
  49. <view class="i-sticky-demo-item">路由</view>
  50. <view class="i-sticky-demo-item">模块化</view>
  51. <view class="i-sticky-demo-item">API</view>
  52. </view>
  53. </i-sticky-item>
  54. <i-sticky-item i-class="i-sticky-demo-title">
  55. <view slot="title">
  56. 插件
  57. </view>
  58. <view slot="content">
  59. <view class="i-sticky-demo-item">注册程序</view>
  60. <view class="i-sticky-demo-item">场景值</view>
  61. <view class="i-sticky-demo-item">注册页面</view>
  62. <view class="i-sticky-demo-item">路由</view>
  63. <view class="i-sticky-demo-item">模块化</view>
  64. <view class="i-sticky-demo-item">API</view>
  65. <view class="i-sticky-demo-item">注册程序</view>
  66. <view class="i-sticky-demo-item">场景值</view>
  67. <view class="i-sticky-demo-item">注册页面</view>
  68. <view class="i-sticky-demo-item">路由</view>
  69. <view class="i-sticky-demo-item">模块化</view>
  70. <view class="i-sticky-demo-item">API</view>
  71. <view class="i-sticky-demo-item">注册程序</view>
  72. <view class="i-sticky-demo-item">场景值</view>
  73. <view class="i-sticky-demo-item">注册页面</view>
  74. <view class="i-sticky-demo-item">路由</view>
  75. <view class="i-sticky-demo-item">模块化</view>
  76. <view class="i-sticky-demo-item">API</view>
  77. </view>
  78. </i-sticky-item>
  79. </i-sticky>
  80. </view>
  1. Page({
  2. data : {
  3. scrollTop : 0
  4. },
  5. onChange(event){
  6. console.log(event.detail,'click right menu callback data')
  7. },
  8. //页面滚动执行方式
  9. onPageScroll(event){
  10. this.setData({
  11. scrollTop : event.scrollTop
  12. })
  13. }
  14. });

API

Sticky properties

属性说明类型默认值
i-class自定义 class 类名String-
scroll-top由于组件内部不能使用 onPageScroll, 导致不能监听 scrollTop 值,所有由用户传递Number-

StickyItem slots

名称说明
title吸顶标题
content内容