这种页面的布局会经常用到,所以在此做个笔记,之后遇到可以节省很多时间

WXML:

<view class='listTitle_tab'>
     <view class='scrollTitle' style='width:{{Width}}px'>
              <view class='listTitle_tab_ltem {{index==0?"on":""}}' data-index="0" bindtap='btnchoose' style='width:{{WidthI}}px;'>标题一</view>
              <view class='listTitle_tab_ltem {{index==1?"on":""}}' data-index="1" bindtap='btnchoose' style='width:{{WidthI}}px; '>标题二</view>
              <view class='listTitle_tab_ltem {{index==2?"on":""}}' data-index="2" bindtap='btnchoose' style='width:{{WidthI}}px; '>标题三</view>
              <view class='listTitle_tab_ltem {{index==3?"on":""}}' data-index="3" bindtap='btnchoose' style='width:{{WidthI}}px;'>标题四</view>
              <view class='listTitle_tab_ltem {{index==4?"on":""}}' data-index="4" bindtap='btnchoose' style='width:{{WidthI}}px;'>标题五</view>
              <view class='listTitle_tab_ltem {{index==5?"on":""}}' data-index="5" bindtap='btnchoose' style='width:{{WidthI}}px;'>标题六</view>
              <view class='listTitle_tab_ltem {{index==6?"on":""}}' data-index="6" bindtap='btnchoose' style='width:{{WidthI}}px; '>标题七</view>
              <view class='listTitle_tab_ltem {{index==7?"on":""}}' data-index="7" bindtap='btnchoose' style='width:{{WidthI}}px;'>标题八</view>
     </view>
</view>
<swiper class='swiper_content' current="{{index}}" bindchange='swiperContent'>
     <swiper-item>我是内容一</swiper-item>
     <swiper-item>我是内容二</swiper-item>
     <swiper-item>我是内容三</swiper-item>
     <swiper-item>我是内容四</swiper-item>
     <swiper-item>我是内容五</swiper-item>
     <swiper-item>我是内容六</swiper-item>
     <swiper-item>我是内容七</swiper-item>
     <swiper-item>我是内容八</swiper-item>
</swiper>
 
CSS:
.listTitle_tab{height: 100rpx;line-height: 100rpx;border-bottom: 1px solid #ccc;background: #e5e5e5;overflow-x: scroll;}
::-webkit-scrollbar{display: none}
.scrollTitle{height: 100rpx;line-height: 100rpx;transition: .3s linear;}
.listTitle_tab_ltem{float: left;text-align: center;position: relative;}
.listTitle_tab_ltem:nth-of-type(2)::before{content: "";position: absolute;left: 0;top: 30rpx;width: 1px;height: 40rpx;background: #ccc}
.listTitle_tab_ltem:nth-of-type(2)::after{content: "";position: absolute;right: 0;top: 30rpx;width: 1px;height: 40rpx;background: #ccc}
.on{color: #ff0000;}
 
 
JS:
var indexNum;
var widthAll;
Page({
     data: {
        index: 0,
     },
onLoad: function (options) {
      var that = this;
      wx.getSystemInfo({
        success: function (res) {
           console.log(res)
           that.setData({
                WidthI: res.windowWidth / 3,
                Width: (res.windowWidth / 3) * 8
           })
          widthAll = res.windowWidth / 3
       },
    })
},
swiperContent: function (res) {
     var that = this;
     that.setData({
          index: res.detail.current
     })
},
btnchoose: function (e) {
      var that = this;
      indexNum = e.currentTarget.dataset.index;
      console.log(indexNum)
      var currentIndex = that.data.index //获取swiper显示的模块的index
      if (indexNum == currentIndex) {
           return false;
      } else {
           that.setData({
                 index: indexNum
           })
     };
 },
})

小程序-TabBar点击切换的更多相关文章

  1. 微信小程序~TabBar底部导航切换栏

    底部导航栏这个功能是非常常见的一个功能,基本上一个完成的app,都会存在一个导航栏,那么微信小程序的导航栏该怎么实现呢?经过无数的踩坑,终于实现了,好了,先看看效果图. 对于底部导航栏,小程序上给出的 ...

  2. 微信小程序 tabBar模板

    tabBar导航栏 小程序tabBar,我们可以通过app.json进行配置,可以放置于顶部或者底部,用于不同功能页面的切换,挺好的... 但,,,貌似不能让动态修改tabBar(需求:通过switc ...

  3. 微信小程序tabbar设置样式在哪里改

    微信小程序tabbar通俗点说就是底部导航,我们一般会配置相关的菜单,方便读者快速导航.tabbar是在项目根目录中的配置文件 app.json 中进行设置:如果小程序是一个多 tab 应用(客户端窗 ...

  4. 小程序tabBar显示问题

    我一直在纠结为什么小程序在有的页面显示,有的页面不显示 查了一下才知道,小程序tabBar只在tabBar中的list定义了页面的才会显示,其余页面不会显示 如下例:tabBar只在画红框的页面显示

  5. 微信小程序实现点击拍照长按录像功能

    微信小程序实现点击拍照长按录像功能 代码里面注释写的都很详细,直接上代码.官方的组件属性中有触摸开始和触摸结束属性.本功能依靠这些属性实现. .wxml代码: <!-- 相机 pages/cam ...

  6. 微信小程序tabBar与redirectTo 或navigateTo冲突

    微信小程序tabBar与redirectTo 或navigateTo冲突 tabBar设置的pagePath无法再次被redirectTo或navigateTo引用 导致跳转失败,更改为swithTa ...

  7. 微信小程序关于tabbar点击切换数据不刷新问题

    微信小程序中经常遇到的需求就是我提交了一个表单或者进行了一个操作,需要在我的个人中心页面中实时显示出来,但是小程序中的tabbar切换类似于tab切换 并不会进行页面刷新请求 所以总是会造成一些数据更 ...

  8. 微信小程序换皮肤,动态切换菜单栏和导航栏的样式,动态修改TabBar和NavigationBar

    在做微信小程序换皮肤的时候,需要动态修改菜单栏(TabBar)和导航栏(NavigationBar) 但是在小程序中它们的样式是写在app.json里面,而且app.json是静态编译,运行时哪怕你修 ...

  9. 小程序 - swiper除了左右切换还有上下滚动超出屏幕的内容

    本来呢,我是有专门整理小程序恶心bug的文章的,每次只要添加汇总就好, 但是呢,鉴于这个问题的恶心程度,所以我把他单独拿出来说了. ---------------------------------- ...

随机推荐

  1. 【android】android对位图文件的支持

    Android 支持以下三种格式的位图文件:.png(首选)..jpg(可接受)..gif(不建议).

  2. 通过源码编译安装VIM

    开发中使用的是Ubuntu 12.04 LTS,通过sudo apt-get install vim安装的版本较低,不支持YCM,所以,用源码编译并安装最新的Vim. 卸载旧版本的Vim: sudo ...

  3. python将excel数据写入数据库,或从库中读取出来

    首先介绍一下SQL数据库的一些基本操作: 1创建 2删除 3写入 4更新(修改) 5条件选择 有了以上基本操作,就可以建立并存储一个简单的数据库了. 放出python调用的代码: 此处是调用dos 操 ...

  4. python GIL锁、进程池与线程池、同步异步

    一.GIL全局解释器锁 全局解释器锁 在CPython中,全局解释器锁(GIL)是一个互斥锁,它可以防止多个本机线程同时执行Python代码.之所以需要这个锁,主要是因为CPython的内存管理不是线 ...

  5. LeetCode(268) Missing Number

    题目 Given an array containing n distinct numbers taken from 0, 1, 2, -, n, find the one that is missi ...

  6. Linux下open函数、read函数、write函数记录

    open() #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> int open( cons ...

  7. 【图文】 使用ant编译和发布java项目

        开发JavaEE项目经常会碰到修改代码后,项目没有重新编译的问题.老大给指明了一个解决办法:用ant编译项目. ant是apache基金会下的一个项目,是基于Java语言的构建工具.      ...

  8. 设计模式(四)建造者模式 Builder

    Builder: <Effective Java> 第2条:遇到多个构造器参数时要考虑用构建器. 建造者模式(Builder Pattern),也称生成器模式,定义如下: 将一个复杂对象的 ...

  9. iOS------手势操作(nib文件、纯代码)

    总共有六种手势识别:轻击手势(TapGestureRecognizer),轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecognizer) ...

  10. 【bzoj3210】花神的浇花集会 旋转坐标系

    题目描述 在花老师的指导下,每周4都有一个集会活动,俗称“浇水”活动. 具体浇水活动详情请见BZOJ3153 但这不是重点 花神出了好多题,每道题都有两个参考系数:代码难度和算法难度 花神为了准备浇花 ...