微信小程序实现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 相关文章推荐
Javascript 学习书 推荐
Jun 13 Javascript
javascript 另一种图片滚动切换效果思路
Apr 20 Javascript
jquery的ajax简单结构示例代码
Feb 17 Javascript
被遗忘的javascript的slice() 方法
Apr 20 Javascript
基于jquery编写的放大镜插件
Mar 23 Javascript
JS组件Bootstrap Table使用实例分享
May 30 Javascript
jQuery Easyui Tabs扩展根据自定义属性打开页签
Aug 15 Javascript
js 创建对象 经典模式全面了解
Aug 16 Javascript
Bootstrap 网格系统布局详解
Mar 19 Javascript
vuejs中父子组件之间通信方法实例详解
Jan 17 Javascript
微信小程序实现底部弹出框
Nov 18 Javascript
详解vue3中组件的非兼容变更
Mar 03 Vue.js
微信小程序实现的点击按钮 弹出底部上拉菜单功能示例
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
PHP人民币金额数字转中文大写的函数代码
2013/02/27 PHP
PHP版微信公众平台红包API
2015/04/02 PHP
Zend Framework教程之资源(Resources)用法实例详解
2016/03/14 PHP
Laravel 简单实现Ajax滚动加载示例
2019/10/22 PHP
基于jquery自己写tab滑动门(通用版)
2012/10/30 Javascript
JQuery拖拽元素改变大小尺寸实现代码
2012/12/10 Javascript
javascript的字符串按引用复制和传递,按值来比较介绍与应用
2012/12/28 Javascript
抛弃Nginx使用nodejs做反向代理服务器
2014/07/17 NodeJs
jQuery中$.ajax()和$.getJson()同步处理详解
2015/08/12 Javascript
基于jquery实现三级下拉菜单
2016/05/10 Javascript
bootstarp modal框居中显示的实现代码
2017/02/18 Javascript
jquery实现楼层滚动效果
2018/01/01 jQuery
详解JS取出两个数组中的不同或相同元素
2019/03/20 Javascript
微信小程序合法域名配置方法
2019/05/06 Javascript
三步实现ionic3点击退出app程序
2019/09/17 Javascript
浅谈Webpack4 Tree Shaking 终极优化指南
2019/11/18 Javascript
js实现点击烟花特效
2020/10/14 Javascript
python使用calendar输出指定年份全年日历的方法
2015/04/04 Python
Python for Informatics 第11章之正则表达式(二)
2016/04/21 Python
Python 正则表达式入门(中级篇)
2016/12/07 Python
python脚本执行CMD命令并返回结果的例子
2019/08/14 Python
Python2比较当前图片跟图库哪个图片相似的方法示例
2019/09/28 Python
基于Python共轭梯度法与最速下降法之间的对比
2020/04/02 Python
使用HTML5 Geolocation实现一个距离追踪器
2018/04/09 HTML / CSS
美国存储和组织商店:The Container Store
2017/08/16 全球购物
欧舒丹美国官网:L’Occitane美国
2018/02/23 全球购物
英国建筑用品在线:Building Supplies Online(BSO)
2018/04/30 全球购物
迪卡侬中国官网:Decathlon中国
2020/08/10 全球购物
沃尔玛旗下墨西哥超市:Bodega Aurrera
2020/11/13 全球购物
回门宴新郎答谢词
2014/01/12 职场文书
连锁酒店店长职责范本
2014/02/13 职场文书
委托书英文
2015/01/28 职场文书
2019最新版劳务派遣管理制度
2019/08/16 职场文书
MySQL磁盘碎片整理实例演示
2022/04/03 MySQL
redis 解决库存并发问题实现数量控制
2022/04/08 Redis
vue+elementUI实现表格列的显示与隐藏
2022/04/13 Vue.js