您当前的位置: 首页 >  微信小程序

微信小程序day02_06之小程序scroll-view可滚动纵向与横向视图组件

发布时间:2019-03-10 12:16:19 ,浏览量:6

文章目录
      • 一 . 可滚动的纵向视图组件
      • 二. 可滚动的横向的组件
一 . 可滚动的纵向视图组件

scroll-view 的属性如下 代码示例 在wxss中, 定义如下的样式

.size { width: 100%; height: 150rpx; } .a { background: red; order: 5; flex: 8 } .b { background: gray; order: 4; flex: 6 } .c { background: yellow; order: 3; flex: 4 } .d { background: orange; order: 2; flex: 2 } .e { background: green; order: 1; flex: 1 } 

在wxml中的代码如下

 <scroll-view scroll-y="true" style='height:250px' bindscrolltoupper="myupperevent" upper-threshold="0" bindscrolltolower="mylowerevent" lower-threshold="0" scroll-top="0" enable-back-to-top="true" scroll-with-animation="false" bindscroll="bindevent" scroll-into-view="c"> <view id='a' class='a size'>a myupperevent: function(){ console.log("到顶部了"); }, mylowerevent: function(){ console.log("到底部了"); }, bindevent: function(){ console.log("绑定滚动事件 "); } }) 

效果如图, 在滚动时会触发一些事件 在页面右侧会出现滚动条

二. 可滚动的横向的组件

要使用横向的组件, 那么就需要把scroll-x属性设置为true 代码示例 在wxm中的代码如下 scroll-left用于指定横向滚动条的起始位置

 <scroll-view class='container' scroll-x="true" style='margin-top:250px' scroll-left="150rpx"> <view id='a' class='a size'>a display: flex; white-space: nowrap /* 不换行 */ } .size { width: 250rpx; height: 350rpx; display: inline-block; } .a { background: red; order: 5; flex: 8 } .b { background: gray; order: 4; flex: 6 } .c { background: yellow; order: 3; flex: 4 } .d { background: orange; order: 2; flex: 2 } .e { background: green; order: 1; flex: 1 } 

显示如下, 可以进行左右的滚动

关注
打赏
1688896170
查看更多评论

暂无认证

  • 6浏览

    0关注

    115984博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0517s