当前位置:网站首页>uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
2022-08-04 23:15:00 【我是开心呀】
效果图:
<!-- 横向选项卡(水平滚动导航栏) -->
<template>
<view>
<!-- 顶部导航栏 -->
<view class="horizonal-tab">
<scroll-view scroll-x="true" scroll-with-animation class="scroll-tab">
<block v-for="(item,index) in tabBars" :key="index">
<view class="scroll-tab-item" :class="{'active': tabIndex==index}" @tap="toggleTab(index)">
{
{
item.name}}
<view class="scroll-tab-line"></view>
</view>
</block>
</scroll-view>
</view>
<!-- 内容区 -->
<view class="content">
<!-- 滑块视图 -->
<swiper :current="tabIndex" @change="tabChange">
<!-- current:当前所在滑块的index -->
<swiper-item v-for="(content,index) in contentList" :key="index">
<view class="content">{
{
content}}</view>
</swiper-item>
</swiper>
</view>
</view>
</template>
<script>
export default {
data() {
return {
tabIndex: 0,
/* 选中标签栏的序列,默认显示第一个 */
contentList: [
"关注",
"推荐",
"热点",
"体育",
'财经',
'娱乐',
'哈',
'哈1',
'哈2',
'哈3',
],
tabBars: [{
name: '关注',
id: 'guanzhu'
},
{
name: '推荐',
id: 'tuijian'
},
{
name: '热点',
id: 'redian'
},
{
name: '体育',
id: 'tiyu'
},
{
name: '财经',
id: 'caijing'
},
{
name: '娱乐',
id: 'yule'
},
{
name: '哈',
id: 'ha'
},
{
name: '哈1',
id: 'ha1'
},
{
name: '哈2',
id: 'ha2'
},
{
name: '哈3',
id: 'ha3'
}
]
}
},
methods: {
//切换选项卡
toggleTab(index) {
this.tabIndex = index;
},
//滑动切换swiper
tabChange(e) {
console.log(e);
this.tabIndex = e.detail.current;
}
}
}
</script>
<style>
.horizonal-tab {
}
.horizonal-tab .active {
color: red;
}
.scroll-tab {
white-space: nowrap;
/* 必要,导航栏才能横向*/
border-bottom: 1rpx solid #eee;
text-align: center;
}
.scroll-tab-item {
display: inline-block;
/* 必要,导航栏才能横向*/
margin: 20rpx 30rpx 0 30rpx;
}
.active .scroll-tab-line {
border-bottom: 5rpx solid red;
border-top: 5rpx solid red;
border-radius: 20rpx;
width: 70rpx;
}
</style>
边栏推荐
猜你喜欢

逆序对的数量

PID控制器改进笔记之七:改进PID控制器之防超调设定

【3D建模制作技巧分享】ZBrush如何重新拓扑

Day118.尚医通:订单列表、详情、支付

使用OpenCV实现一个文档自动扫描仪

社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力

To Offer | 03. Repeat Numbers in the array

If you can't get your heart, use "distributed lock" to lock your people

【转载】kill掉垃圾进程(在资源管理器占用的情况下)

【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
随机推荐
kernel问题定位手段总结
Will we still need browsers in the future?(feat. Maple words Maple language)
web3.js
一点点读懂cpufreq(二)
node中package解析、npm 命令行npm详解,node中的common模块化,npm、nrm两种方式查看源和切换镜像
基于内容的图像检索系统设计与实现--颜色信息--纹理信息--形状信息--PHASH--SHFT特征点的综合检测项目,包含简易版与完整版的源码及数据!
【字符串函数内功修炼】strcpy + strcat + strcmp(一)
FinClip崁入式搭建生态平台,降低合作门槛
The market value of 360 has evaporated by 390 billion in four years. Can government and enterprise security save lives?
直接插入排序
年薪50W+的测试工程师都在用这个:Jmeter 脚本开发之——扩展函数
一点点读懂cpufreq(一)
PHP(3)
Service Mesh landing path
地面高度检测/平面提取与检测(Fast Plane Extraction in Organized Point Clouds Using Agglomerative Hierarchical Clu)
Service Mesh落地路径
Community Sharing|Tencent Overseas Games builds game security operation capabilities based on JumpServer
Literature reading ten - Detect Rumors on Twitter by Promoting Information Campaigns with Generative Adversarial Learn
【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
【3D建模制作技巧分享】ZBrush纹理贴图怎么导入