position: sticky在小程序中IOS真机下偶然失效的问题总结

2021-08-1907:38:03APP与小程序开发Comments1,977 views字数 869阅读模式

小程序中有大把的自定义sticky组件可用,原理无非是监听页面滚动改变position来实现,实际体验上卡顿感难以避免,跟原生的position: sticky比还是有很大距离。
最近写的页面已经开始逐渐用上原生position: sticky,在测试中发现IOS真机下,某些场景的sticky会失效,花了点时间研究,得出来以下结论:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

  1. IOS必须加上position: -webkit-sticky;
  2. IOSsticky的元素必须与占位元素在同一个作用域下面,才生效

直接在页面中写sticky有效

page.wxml文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

<view style="height: 100px">title</view>
<view style="position: -webkit-sticky; position: sticky; top: 40px">sticky</view>
<view style="height: 200vh"></view>

sticky定义在组件内,占位元素在页面里,安卓及模拟器有效,IOS真机无效

components.wxml文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

<view style="position: -webkit-sticky; position: sticky; top: 40px">sticky</view>

page.wxml文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

<view style="height: 100px">title</view>
<components/>
<view style="height: 200vh"></view>

sticky定义在组件内,占位元素在组件插槽内,有效

components.wxml文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

<view style="position: -webkit-sticky; position: sticky; top: 40px">sticky</view>
<slot/>

page.wxml文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

<view style="height: 100px">title</view>
<components>
  <view style="height: 200vh"></view>
</components>

第二个真的是神坑,还好可以通过第三个办法解决文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22149.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/xcx/22149.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定