Tab switching effect of WeChat applet

The tab switching effect of the WeChat applet, as shown in the figure:

Recently, I am learning WeChat mini-programs and moving the previous company app to the mini-programs, and record some implementation effects (mainly not mentioned in the official documents, after all, the official documents only introduce functions)

.wxml code:

<view class="body">
  <view class="nav bc_white">
    <view class="{ {selected?'red':'default'}}" bindtap="selected">系统提醒</view>
    <view class="{ {selected1?'red':'default'}}" bindtap="selected1">优惠活动</view>
  </view>
  <view class="{ {selected?'show':'hidden'}}">for system</view>
  <view class="{ {selected1?'show':'hidden'}}">for activity</view>
</view>

.wxss code :

page{background-color:#edf0f3;}
.nav{width:100%;height:100rpx;display:flex;flex-direction:row;}
.default{line-height:100rpx;text-align:center;flex:1;border-right:1px solid gainsboro;color:#000;font-weight:bold;font-size:28rpx;}
.red{line-height:100rpx;text-align:center;color:#fc5558;flex:1;border-right:1px solid gainsboro;font-weight:bold;font-size:28rpx;}
.show{display:block;text-align:center;line-height:200rpx;}
.hidden{display:none;text-align:center;line-height:200px;}

.js code:

Page({
    data:{
        selected:true,
        selected1:false
        },
    selected:function(e){
        this.setData({
            selected1:false,
            selected:true
        })
    },
    selected1:function(e){
        this.setData({
            selected:false,
            selected1:true
        })
    }
})

Guess you like

Origin blog.csdn.net/liona_koukou/article/details/52860094