当前位置:首页站长学院后端开发微信小程序滚动视图容器如何实现的
企业营销,就选知企PROSAAS

微信小程序滚动视图容器如何实现的

本文主要介绍了微信小程序之滚动视图容器的实现方法的相关资料,希望通过本文能帮助到大家,让大家掌握这部分内容,需要的朋友可以参考下,希望能帮助到大家。

微信小程序之滚动视图容器的实现方法

直接上两种方案代码以及效果图:

方案1

这种方案是直接使用view,并设置overflow: scroll

wxml:
 <view class="container">
  <view class="content" wx:for="{{11}}" wx:key="item">
    {{item}}
  </view>
</view>

wxss:

 .container {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  overflow: scroll;
  padding-bottom: 20rpx;
  background: #FD9494;
}

.content {
  margin: 20rpx auto 0 auto;
  width: 710rpx;
  height: 300rpx;
  background: #ddd;
  border-radius: 16rpx;
  font-size: 80rpx;
  line-height: 300rpx;
  text-align: center;
}

效果图:

微信小程序滚动视图容器如何实现的

方案2

使用scroll-view + container作为容器

wxml:

<scroll-view class="main_container" scroll-y>
  <view class="container">
    <view class="content" wx:for="{{11}}" wx:key="item">
      {{item}}
    </view>
  </view>
</scroll-view>

wxss:

.main_container {
  position: relative;
  width: 750rpx;
  height: 100vh;
  background: #FD9494;
}

 .container {
  position: absolute; /*使用absolute的原因是因为为了防止第一个子视图有margin-top时,造成顶部留白的情况*/
  left: 0;
  top: 0;
  width: 100%;
  padding-bottom: 20rpx;
} 

.content {
  margin: 20rpx auto 0 auto;
  width: 710rpx;
  height: 300rpx;
  background: #ddd;
  border-radius: 16rpx;
  font-size: 80rpx;
  line-height: 300rpx;
  text-align: center;
}

效果图:

微信小程序滚动视图容器如何实现的

对比结果:

因为iPhone上滚动会带有弹簧效果,所以方案1在滚动时会出现不流畅的现象。方案2就不会出现这种情况,而且滚动也是流畅的。

方案2是我目前总结出来的比较好的滚动视图方案。

相关推荐:

微信小程序开发之滑块视图容器

推荐10款视图容器源码(收藏)

微信小程序:view(视图容器 )组件解读和分析

以上就是微信小程序滚动视图容器如何实现的的详细内容,更多请关注知企PROSAAS其它相关文章!

温馨提示:

文章标题:微信小程序滚动视图容器如何实现的

文章链接:https://ceshi.prosaas.cn/17755.html

更新时间:2018年01月31日

声明: 本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:973664285@qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读知企PROSAAS协议

给TA打赏
共{{data.count}}人
人已打赏
后端开发

微信小程序获取openid及用户信息的方法

2018-1-31 9:53:12

后端开发

Vuex模块化(module)实例详解

2018-1-31 13:47:38

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索