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

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. javascript实现原生ajax的几种方法介绍

    自从javascript有了各种框架之后,比如jquery,使用ajax已经变的相当简单了.但有时候为了追求简洁,可能项目中不需要加载jquery这种庞大的js插件.但又要使用到ajax这种功能该如何 ...

  2. Pytorch学习(一)—— 自动求导机制

    现在对 CNN 有了一定的了解,同时在 GitHub 上找了几个 examples 来学习,对网络的搭建有了笼统地认识,但是发现有好多基础 pytorch 的知识需要补习,所以慢慢从官网 API进行学 ...

  3. python基本数据类型和简单用法

    一.int 整形范围 How Big Is an int? In Python2, the size of an int was limited to 32 bits, which is enough ...

  4. Applied Nonparametric Statistics-lec9

    Ref:https://onlinecourses.science.psu.edu/stat464/print/book/export/html/12 前面我们考虑的情况是:response是连续的, ...

  5. leetcode-12-stack

    409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...

  6. bootmem_init_node

    static unsigned long __init bootmem_init_node(int node, struct meminfo *mi) in arch/arm/mm/init.c 1. ...

  7. 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

    131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...

  8. TCP的三次握手和四次握手

    三次握手(建立连接) 首先,服务器进程(B)先创建传控制块TCB(用来存储连接信息,如连接表,发送和接收序号等),准备接收客户进程(A)的请求.然后服务器进程处于LISTEN(收听)状态,等待客户的连 ...

  9. Linux学习-systemctl 针对 service 类型的配置文件

    systemctl 配置文件相关目录简介 现在我们知道服务的管理是透过 systemd,而 systemd 的配置文件大部分放置于 /usr/lib/systemd/system/ 目录内. 该目录的 ...

  10. 各浏览器对 window.open() 的支持

    原文地址