微信小程序实现swiper切换卡内嵌滚动条不显示的方法示例


Posted in Javascript onDecember 20, 2018

本文实例讲述了微信小程序实现swiper切换卡内嵌滚动条不显示的方法。分享给大家供大家参考,具体如下:

微信小程序实现swiper切换卡内嵌滚动条不显示的方法示例

index.wxml文件:

<view class="swiper-tab">
 <view class="swiper-tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">为你推荐</view>
 <view class="swiper-tab-item {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">新品上架</view>
 <view class="swiper-tab-item {{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav">最热商品</view>
</view>
<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{clientHeight?clientHeight-'40'+'px':'auto'}}" bindchange="bindChange" >
 <swiper-item>
 <scroll-view scroll-y="{{true}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}">
  <view style='height:200px'>为你推荐</view>
  <view style='height:200px'>为你推荐</view>
  <view style='height:200px'>为你推荐</view>
  <view style='height:200px'>为你推荐</view>
  <view style='height:200px'>为你推荐</view>
 </scroll-view>
 </swiper-item>
 <swiper-item>
  <view>新品上架</view>
 </swiper-item>
 <swiper-item>
  <view>最热商品</view>
 </swiper-item>
</swiper>

index.wxss文件:

/**index.wxss**/
.userinfo {
 display: flex;
 flex-direction: column;
 align-items: center;
}
.userinfo-avatar {
 width: 128rpx;
 height: 128rpx;
 margin: 20rpx;
 border-radius: 50%;
}
.userinfo-nickname {
 color: #aaa;
}
.usermotto {
 margin-top: 200px;
}
.swiper-tab {
 width: 100%;
 text-align: center;
 line-height: 80rpx;
 margin-top:10rpx;
 margin-bottom: 20rpx;
}
.swiper-tab-item {
 font-size: 30rpx;
 display: inline-block;
 width: 33.33%;
 color: #666;
}
.on {
 color: #FEA611;
 border-bottom: 5rpx solid #FEA611;
}
.swiper-box {
 display: block;
 height: 100%;
 width: 100%;
 overflow: hidden;
}
.swiper-box view {
 text-align: center;
}

index.js文件:

//获取应用实例
const app = getApp()
Page({
 data: {
  motto: 'Hello World',
  userInfo: {},
  hasUserInfo: false,
  canIUse: wx.canIUse('button.open-type.getUserInfo'),
  clientWidth: 0,
  clientHeight: 0,
  // tab切换
  currentTab: 0
 },
 //事件处理函数
 bindViewTap: function () {
  wx.navigateTo({
   url: '../logs/logs'
  })
 },
 onLoad: function () {
  var that = this;
  wx.getSystemInfo({
   success: function (res) {
    that.setData({
     clientHeight: res.windowHeight
    });
   }
  });
  if (app.globalData.userInfo) {
   this.setData({
    userInfo: app.globalData.userInfo,
    hasUserInfo: true
   })
  } else if (this.data.canIUse) {
   // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
   // 所以此处加入 callback 以防止这种情况
   app.userInfoReadyCallback = res => {
    this.setData({
     userInfo: res.userInfo,
     hasUserInfo: true
    })
   }
  } else {
   // 在没有 open-type=getUserInfo 版本的兼容处理
   wx.getUserInfo({
    success: res => {
     app.globalData.userInfo = res.userInfo
     this.setData({
      userInfo: res.userInfo,
      hasUserInfo: true
     })
    }
   })
  }
 },
 getUserInfo: function (e) {
  console.log(e)
  app.globalData.userInfo = e.detail.userInfo
  this.setData({
   userInfo: e.detail.userInfo,
   hasUserInfo: true
  })
 },
 bindChange: function (e) {
  var that = this;
  that.setData({ currentTab: e.detail.current });
 },
 swichNav: function (e) {
  var that = this;
  if (this.data.currentTab === e.target.dataset.current) {
   return false;
  } else {
   that.setData({
    currentTab: e.target.dataset.current
   })
  }
 }
})

希望本文所述对大家微信小程序开发有所帮助。

Javascript 相关文章推荐
window.addEventListener来解决让一个js事件执行多个函数
Dec 26 Javascript
Js nodeType 属性全面解析
Nov 14 Javascript
jquery简单的弹出层浮动层代码
Apr 27 Javascript
在JavaScript中模拟类(class)及类的继承关系
May 20 Javascript
深入理解JS DOM事件机制
Aug 06 Javascript
JavaScript数据结构之广义表的定义与表示方法详解
Apr 12 Javascript
JS实现前端缓存的方法
Sep 21 Javascript
浅谈JavaScript的innerWidth与innerHeight
Oct 12 Javascript
vuejs实现ready函数加载完之后执行某个函数的方法
Aug 31 Javascript
解决layui弹框失效的问题
Sep 09 Javascript
vue实现商品列表的添加删除实例讲解
May 14 Javascript
Vuex的各个模块封装的实现
Jun 05 Javascript
微信小程序实现的点击按钮 弹出底部上拉菜单功能示例
Dec 20 #Javascript
vue+Vue Router多级侧导航切换路由(页面)的实现代码
Dec 20 #Javascript
微信小程序module.exports模块化操作实例浅析
Dec 20 #Javascript
JavaScript类的继承操作实例总结
Dec 20 #Javascript
vue返回上一页面时回到原先滚动的位置的方法
Dec 20 #Javascript
详解Vue.js自定义tipOnce指令用法实例
Dec 19 #Javascript
JavaScript创建对象方式总结【工厂模式、构造函数模式、原型模式等】
Dec 19 #Javascript
You might like
基于mysql的bbs设计(二)
2006/10/09 PHP
在PHP中使用Sockets 从Usenet中获取文件
2008/01/10 PHP
php自动适应范围的分页代码
2008/08/05 PHP
php 连接mysql连接被重置的解决方法
2011/02/15 PHP
php 生成文字png图片的代码
2011/04/17 PHP
PHP 基于文件头的文件类型验证类函数
2012/05/01 PHP
PHP将XML转数组过程详解
2013/11/13 PHP
PHP统计数值数组中出现频率最多的10个数字的方法
2015/04/20 PHP
PHP常用工具函数小结【移除XSS攻击、UTF8与GBK编码转换等】
2019/04/27 PHP
phpQuery采集网页实现代码实例
2020/04/02 PHP
Jquery替换已存在于element上的event的方法
2010/03/09 Javascript
jquery实现手风琴效果实例代码
2013/11/15 Javascript
jquery插件推荐 jquery.cookie
2014/11/09 Javascript
JS实现图片平面旋转的方法
2016/03/01 Javascript
vue路由嵌套的SPA实现步骤
2017/11/06 Javascript
Parcel 打包示例(React HelloWorld)
2018/01/16 Javascript
详解React中共享组件逻辑的三种方式
2021/02/02 Javascript
nestjs中异常过滤器Exceptionfilter的具体使用
2021/02/07 Javascript
[55:25]2018DOTA2亚洲邀请赛3月29日 小组赛A组 VG VS OG
2018/03/30 DOTA
python写的ARP攻击代码实例
2014/06/04 Python
python脚本内运行linux命令的方法
2015/07/02 Python
网站渗透常用Python小脚本查询同ip网站
2017/05/08 Python
python中使用正则表达式的连接符示例代码
2017/10/10 Python
python: 判断tuple、list、dict是否为空的方法
2018/10/22 Python
学python安装的软件总结
2019/10/12 Python
selenium+headless chrome爬虫的实现示例
2021/01/08 Python
size?德国官方网站:英国伦敦的球鞋精品店
2018/03/17 全球购物
DataList 能否分页,请问如何实现?
2015/05/03 面试题
商务会议邀请函
2014/01/09 职场文书
优秀党支部事迹材料
2014/01/14 职场文书
员工入职担保书范文
2014/04/01 职场文书
五一促销活动总结
2014/07/01 职场文书
2014年妇联工作总结
2014/11/21 职场文书
幼儿园家长反馈意见
2015/06/03 职场文书
2016入党心得体会范文
2016/01/06 职场文书
vue3种table表格选项个数的控制方法
2022/04/14 Vue.js