类似taro-ui tab切换的导航动画

类似这个切换的动画
https://taro-ui.jd.com/#/docs/tabs
在这里插入图片描述

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.scss'

export default class repairmanList extends Component {
  config = {
    navigationBarTitleText: '商品列表'
  }
  constructor() {
    super(...arguments)
    this.state = {
      currentIndex: 0,
      navList: [{
        id: 1,
        title: '综合排序',
      }, {
        id: 2,
        title: '距离近',
      }, {
        id: 3,
        title: '销量',
      }, {
        id: 4,
        title: '价格排序',
      }]
    }
  }

  changeNavState(v) {
    this.setState(() => {
      return {
        currentIndex: v
      };
    });
  }


  render() {
    return (
      <View className='repairman-list__container'>
        <View className='nav-title'>
          {
            navList.map((item, index) => (
              <View className='nav-title__item'
                onClick={this.changeNavState.bind(this, index)}
                key={item.title}
              >
                <View className={['txt', index === this.state.currentIndex ? "txt_active" : null]}>{item.title}</View>
                <View className={`border ${index === this.state.currentIndex ? "border_active" : null}`}></View>
              </View>
            ))
          }
        </View>
      </View>
    )
  }
}

 .nav-title {
    height: 84px;
    display: flex;
    justify-content: space-around;
    background: white;
    border-bottom: 1px solid #aaaaaa;
    position: fixed;
    z-index: 1;
    width: 100vw;
    top: 0;

    &__item {
      width: 112px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
	  transition: color 0.2s;
	  
	    .txt {
	        font-size: 28px;
	        font-family: PingFangSC-Regular;
	        font-weight: 400;
	        color: rgba(153, 153, 153, 1);
	        transition: color 0.2s;
	        &_active {
		        color: rgba(3, 118, 232, 1);
		    }
	      }
	
	  
	      .border {
	        position: absolute;
	        bottom: 0;
	        width: 0px;
	        height: 2px;
	        background: white;
	        border-radius: 1px;
	        transition: width 0.2s;	
	        &_active {
		        background: rgba(3, 118, 232, 1);
		        width: 112px;
	     	 }
	      }
    }
  }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值