zoukankan      html  css  js  c++  java
  • 小程序头部滑动切换

    <scroll-view scroll-x class="navbar" scroll-with-animation scroll-left="{{scrollLeft}}rpx">
      <view class="nav-item" wx:for="{{tabs}}" wx:key="id" bindtap="tabSelect" data-id="{{index}}">
        <view class="nav-text {{index==tabCur?'tab-on':''}}">{{item.name}}</view>
      </view>
    </scroll-view>
     
     
     
    .navbar {
       100%;
      height: 90rpx;
      /* 文本不换行 */
      white-space: nowrap;
      display: flex;
      box-sizing: border-box;
      border-bottom: 1rpx solid #eee;
      background: #fff;
      align-items: center;
      /* 固定在顶部 */
      position: fixed;
      left: 0rpx;
      top: 0rpx;
    }

    .nav-item {
      padding-left: 25rpx;
      padding-right: 25rpx;
      height: 100%;
      display: inline-block;
      /* 普通文字大小 */
      font-size: 28rpx;
    }

    .nav-text {
       100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      letter-spacing: 4rpx;
      box-sizing: border-box;
    }

    .tab-on {
      color: #2997C6;
      /* 选中放大 */
      font-size: 38rpx !important;
      font-weight: 600;
      border-bottom: 4rpx solid #2997C6 !important;
    }
     
     
     
     
     
     
     
     
    Page({
      data: {
        tabCur: 0, //默认选中
        tabs: [{
          name: '栏目一',
          id: 0
         },
         {
          name: '栏目二',
          id: 1
         },
         {
          name: '栏目三',
          id: 2
         },
         {
          name: '栏目一',
          id: 3
         },
         {
          name: '栏目一',
          id: 4
         },
      ]

    },

    //选择条目
    tabSelect(e) {
    this.setData({
    tabCur: e.currentTarget.dataset.id,
    scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
    }
    })
  • 相关阅读:
    虚方法、重写方法和抽象方法[转载]
    枚举的默认构造为第一个成员值!
    自定义Attribute例子!
    Python 处理MD5
    php5 反射refection 的用途
    python Sleep休眠函数
    python处理urlencode的两种方式
    python操作mysql进行更新的时候,必须有commit
    Python repr() 或str() 函数
    python抓取网页内容
  • 原文地址:https://www.cnblogs.com/weiweiyeyu/p/12015463.html
Copyright © 2011-2022 走看看