微信小程序tab页面切换

在这里插入图片描述
html 页面

<view class="bgwhite">
    <scroll-view scroll-x="true">
        <view class="width100 row nowrap">
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 0 ? 'topic' : ''}}" data-current="0" bindtap='checkCurrent'>1</view>
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 1 ? 'topic' : ''}}" data-current="1" bindtap='checkCurrent'>2</view>
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 2 ? 'topic' : ''}}" data-current="2" bindtap='checkCurrent'>3</view>
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 3 ? 'topic' : ''}}" data-current="3" bindtap='checkCurrent'>4</view>
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 4 ? 'topic' : ''}}" data-current="4" bindtap='checkCurrent'>5</view>
            <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 5 ? 'topic' : ''}}" data-current="5" bindtap='checkCurrent'>6</view>
        </view>
    </scroll-view>
</view>
<swiper current="{{currentData}}" class='width100' style="height:600px;" duration="300" bindchange="bindchange">
    <swiper-item>
        <view class="m-lr-20">
            <view class="row p-t-30 p-b-10">
                <view class="radio_singel f22 p-lr-10">单选</view>
                <view class="m-l-20 weight500 f28">题目1</view>
            </view>
            <radio-group bindchange="radioChange">
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio checked="true" color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">A1111</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">B2222</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">C3333</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">D4444</view>
                </label>
            </radio-group>
        </view>
    </swiper-item>
    <swiper-item>
        <view class="m-lr-20">
            <view class="row p-t-30 p-b-10">
                <view class="radio_singel f22 p-lr-10">单选</view>
                <view class="m-l-20 weight500 f28">题目2</view>
            </view>
            <video src="" style="width:100%;"></video>
            <radio-group bindchange="radioChange">
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio checked="true" color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">A1111</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">B2222</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">C3333</view>
                </label>
                <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20">
                <view class="weui-cell__hd">
                    <radio color="#1989f9"/>
                </view>
                <view class="f30 weight500 m-l-10">D4444</view>
                </label>
            </radio-group>
        </view>
    </swiper-item>
    <swiper-item>
    </swiper-item>
    <swiper-item>
    </swiper-item>
    <swiper-item>
    </swiper-item>
</swiper>

<view class="footer p-tb-25">
    <view class="m-lr-30 row just-btw">
        <view class="row alignitems" bindtap="prevClick">
            <image src="../../images/prev_icon.png" mode="aspectFit" style="width:48rpx;height:42rpx;"></image>
            <view class="f36 weight500 m-l-10">上一题</view>
        </view>
        <view class="jiaojuanbtn f30 white p-tb-20">交卷</view>
        <view class="row alignitems" bindtap="nextClick">
            <view class="f36 weight500 m-r-10">下一题</view>
            <image src="../../images/next_icon.png" mode="aspectFit" style="width:48rpx;height:42rpx;"></image>
        </view>
    </view>
</view>

css样式

.topic{
    position: relative;
    color:#000;
}
.topic::before{
    position: absolute;
    content:"";
    width:80rpx;
    height:6rpx;
    background: #1989f9;
    border-radius: 20rpx;
    bottom: 0;
    left:50%;
    transform: translateX(-50%);
}
.radio_singel{
    background: #e6f7ff;
    border:1px solid #91d4fe;
    color:#1890ff;
}
.footer{
    position: fixed;
    bottom: 0;
    background-color: #fff;
    left:0;
    right:0;
}

js 页面

	data: {
        currentData:0,
    },
	//获取当前滑块的index
    bindchange(e){
        const that  = this;
        that.setData({
            currentData: e.detail.current
        })
    },
    //点击切换,滑块index赋值
    checkCurrent(e){
        const that = this;

        if (that.data.currentData === e.target.dataset.current){
            return false;
        }else{
            that.setData({
                currentData: e.target.dataset.current
            })
        }
    },
    //上一题
    prevClick(){
        var currentData = this.data.currentData - 1
        if(currentData + 1 == 0){
            wx.showToast({
              title: '这是第1题了',
            })
        }else{
            this.setData({
                currentData:currentData
            })
        }
    },
    //下一题
    nextClick(){
        this.setData({
            currentData:this.data.currentData + 1
        })
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张张Z7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值