微信小程序 scroll-view横向滚动,实现写法

一开始实现不了,搜的看了三四篇,并没觉得有什么用。也并没理解他们说的 跟inline-block影响很大;想了想竖向的原理,觉得应该这样,且已实现滚动。

直接代码(展示五个,超过五个滚动,这写死了)(这主要是在scroll-view的下一级元素 view class=flex-wrap 动态赋值宽度):

<scroll-view scroll-x="true" scroll-left="{{scrollLeftWidth}}" 
		bindscroll="scrollleft"
        scroll-with-animation='true'
        bindscrolltolower="lowerRight">
	  <view class="flex-wrap sertit-dis" style='width:{{scrollWidth}}px;'>
	    <view class='flex-item'>
	      <text>菜单一</text>
	    </view>
	    <view class='flex-item'>
	      <text>菜单二</text>
	    </view>
	    <view class='flex-item'>
	      <text>菜单三</text>
	    </view>
	    <view class='flex-item'>
	      <text>菜单四</text>
	    </view>
	    <view class='flex-item'>
	      <text>菜单五</text>
	    </view>
	    <view class='flex-item'>
	      <text>菜单六</text>
	    </view>
	  </view>
</scroll-view>
Page({
	data: {
	    scrollWidth:0,
	    scrollLeftWidth:0,
	    windowWidth:0
	},
	onLoad:function(){
		var that = this;
		that.getScrollWidth();
	},
	getScrollWidth: function () {
	    var scrollWidth = wx.getSystemInfoSync().windowWidth;
	    this.setData({
	      scrollWidth: scrollWidth/5 * 6,
	      windowWidth: scrollWidth
	    })
	 },
	 scrollleft:function(e){
	    console.log(e);
	 },
	 lowerRight:function(e){
	    console.log(e);
	 },
})

.flex-wrap{
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-around;
  height:40px;
}
.sertit-dis .flex-item{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

//滑动前(我原页面是有写好的模仿进度条,为了方便看,scroll-view上的事件都可触发,lowerRight,scrollleft)
在这里插入图片描述
//滑动后
在这里插入图片描述

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值