博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序-TabBar点击切换
阅读量:7091 次
发布时间:2019-06-28

本文共 2835 字,大约阅读时间需要 9 分钟。

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

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
           })
     };
 },
})

转载于:https://www.cnblogs.com/liuqingxia/p/8566316.html

你可能感兴趣的文章
界面无小事(二): 让RecyclerView展示更多不同视图
查看>>
关于C++、PHP和Swoole
查看>>
linux日志系统
查看>>
AV1挑起的Codec之战
查看>>
虚拟环境的配置
查看>>
.NET快速信息化系统开发框架 V3.2-Web版本“产品管理”事例编辑界面新增KindEditor复文本编辑控件...
查看>>
浅谈直播行业发展前景和发展方向
查看>>
2- OpenCV+TensorFlow 入门人工智能图像处理-opencv入门
查看>>
java.lang.Integer源码精读(一)
查看>>
Flink1.4 窗口触发器与Evictors
查看>>
几个与文本处理相关的Linux命令总结
查看>>
django模板详解(二)
查看>>
ASM概述
查看>>
手动删除数据库 oracle
查看>>
浅析ConcurrentHashMap
查看>>
html中header结构详解
查看>>
日常使用
查看>>
jQuery实现还能输入N字符
查看>>
su命令
查看>>
使用Wisdom RESTClient进行自动化测试,如何取消对返回的body内容的校验?对排除的JSON属性字段不做校验?...
查看>>