温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

微信小程序怎么实现tab页面切换效果

发布时间:2022-08-25 10:36:49 来源:亿速云 阅读:178 作者:iii 栏目:开发技术

这篇文章主要讲解了“微信小程序怎么实现tab页面切换效果”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“微信小程序怎么实现tab页面切换效果”吧!

效果图

微信小程序怎么实现tab页面切换效果

html 页面

<view class="bgwhite">
    <scroll-view scroll-x="true">
        <view class="width200 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='width200'  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">A、1111</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">B、2222</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">C、3333</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">D、4444</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="" ></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">A、1111</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">B、2222</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">C、3333</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">D、4444</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" ></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" ></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
        })
    },

感谢各位的阅读,以上就是“微信小程序怎么实现tab页面切换效果”的内容了,经过本文的学习后,相信大家对微信小程序怎么实现tab页面切换效果这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI