前端特效:小程序导航滑动衔接

本文介绍了一种使用WXML和WXSS结合JS实现动态Tab切换的方法,通过绑定事件和条件渲染,实现了不同状态下的界面切换效果。同时,通过Swiper组件和自定义样式,确保了页面布局的响应式和美观。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

                     

html部分:

<view class='all'>

<view class='head'>

<view class='{{number==0?"one":"color"}}' bindtap='change' data-id='0'>未使用<view></view></view>

<view class='{{number==1?"one":"color"}}' bindtap='change' data-id='1'>已使用<view></view></view>

<view class='{{number==2?"one":"color"}}' bindtap='change' data-id='2'>已失效<view></view></view>

</view>

<swiper class='box' bindchange="swiperChange" circular current='{{index}}'>

<swiper-item> 填写未使用这部分的内容</swiper-item>

<swiper-item>填写已使用这部分的内容</swiper-item>

<swiper-item>填写已失效这部分的内容</swiper-item>

</swiper>

</view>

css样式

.all{

width: 100%;

height: 100%;

position: fixed;

top: 0;

left: 0;

border-top: 1px solid #d6d6d6;

}

.head{

width: 100%;

height: 100rpx;

background: #fffbf2;

display: flex;

line-height: 100rpx;

}

.head>.one,.head>.color{

flex: auto;

text-align: center;

color: #f1a529;

font-size: 30rpx;

position: relative;

font-weight: 600

}

.head>.color{

color: #222

}

.head>.one view{

width: 60rpx;

height: 5rpx;

background: #f1a529;

position: absolute;

left: 0;

right: 0;

margin: auto;

bottom: 0;

}

.head>.color view{

width: 60rpx;

height: 5rpx;

background: transparent;

position: absolute;

left: 0;

right: 0;

margin: auto;

bottom: 0;

}

.box{

width: 100%;

height: 95%;

}

.box .two{

width: 100%;

height: 100%;

overflow-y: auto

}

 

js部分

data: {

number: 0,

index: 0

},

 

//主体滑动

swiperChange(e) {

var that = this

that.setData({

number: e.detail.current

})

console.log(e.detail.current)

console.log(that.data.number)

},

 

//点击导航标题 ,主体滑块跟随移动

change(e) {

var that = this

console.log(e.currentTarget.dataset.id)

if (e.currentTarget.dataset.id === that.data.index) {

return false

} else {

that.setData({

index: e.currentTarget.dataset.id

})

}

},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值