微信小程序- 实现横向滑动列表

1. 微信小程序-实现横向滑动列表

  微信小程序如何隐藏scroll-view滚动条
  
在这里插入图片描述

1.1. photoScroll.wxml

<view class="hs-body">
  <scroll-view class="hs-layout" scroll-x="true" scroll-left="{{x}}" scroll-with-animation="{{true}}">
    <view class="hs-item-layout" wx:for="{{nav_list}}" wx:key="item" data-type="item">
      <view class="hs-item-body" bindtap='exampleClick' data-item-id="{{item.id}}">
        <view class="hs-item-Inner-layout">
          <view class="hs-item-title">标题</view>
          <view class="hs-item-label">标签 </view>
        </view>
        <image class="hs-item-img" src="../../image/icon/icon_apply_menu.png" mode="aspectFit">
        </image>
      </view>
    </view>
  </scroll-view>
</view>

1.2. photoScroll.wxss

.hs-body {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  line-height: 40rpx;
}

.hs-layout {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  line-height: 40rpx;
}

.hs-item-layout {
  display: inline-block;
  white-space: normal;
  text-align: center;
  font-size: 26rpx;
}

::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
.hs-item-Inner-layout{
  position: absolute;
  left: 0;
  top: 0;
  color: #fff;
  font-size: 21rpx;
  border-bottom-right-radius: 18rpx;
  float: left;
  padding: 8rpx 10rpx;
  display: flex;
  flex-direction: column;
  margin: 20rpx 20rpx;
}
.hs-item-body {
  display: flex;
  width: 180rpx;
  height: 160rpx;
  position: relative;
 
}



.hs-item-title {
  color: #000;
  font-size: 24rpx;
  overflow: hidden;
  text-overflow: -o-ellipsis-lastline;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.hs-item-label {
  color: #666;
  font-size: 24rpx;
  margin-top: 5rpx;
  padding: 0 20rpx;
  background: #3691FB;
  border-radius: 20rpx;
  overflow: hidden;
  text-overflow: -o-ellipsis-lastline;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.hs-item-img {
  width: 180rpx;
  height: 160rpx;
}

1.3. photoScroll.js

// pages/photoScroll/photoScroll.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav_list: ['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'],
    currentTab: '' //当前选中的月份下标从0开始
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  onShow() {

  },
    //点击月
    async swichNav(e) {
      var current = e.target.dataset.index
      if (this.data.currentTab != current) {
        this.setData({ currentTab: current })
      }
      // 点击的月份
      var mon = 12 - current
      if (mon < 10) {
        mon = '0' + mon
      }
      console.log('当前月份:' + mon)
    }
})

1.4. 【scroll-view】组件【scroll-x】设置为true后仍然不能横向滑动的问题

  【scroll-view】组件【scroll-x】设置为true后仍然不能横向滑动的问题
  scroll-view在ios上没有显示滚动条,如果在安卓设备上会显示一个滚动条
  注:因为在手机上看的话会有横向滚动条,下面这个css代码能去掉横向滚动条

::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值