当前位置:网站首页>uniapp horizontal tab (horizontal scrolling navigation bar) effect demo (organization)
uniapp horizontal tab (horizontal scrolling navigation bar) effect demo (organization)
2022-08-04 23:19:00 【I am happy】
效果图:
<!-- horizontal tab(Scrolls the navigation bar horizontally) -->
<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;
/* 必要,The navigation bar can only be horizontal*/
border-bottom: 1rpx solid #eee;
text-align: center;
}
.scroll-tab-item {
display: inline-block;
/* 必要,The navigation bar can only be horizontal*/
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>
边栏推荐
猜你喜欢

【SSR服务端渲染+CSR客户端渲染+post请求+get请求+总结】

web3.js
![[Cultivation of internal skills of string functions] strcpy + strcat + strcmp (1)](/img/b6/5a1c8b675dc7f67f359c25908403e1.png)
[Cultivation of internal skills of string functions] strcpy + strcat + strcmp (1)

Shell编程之循环语句与函数的使用

【3D建模制作技巧分享】ZBrush如何使用Z球

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

xss总结

Community Sharing|Tencent Overseas Games builds game security operation capabilities based on JumpServer

仪表板展示 | DataEase看中国:数据呈现中国资本市场

加解密在线工具和进制转化在线工具
随机推荐
C语言实现扫雷 附带源代码
学生管理系统架构设计
typeScript-promise
VC bmp文件总结
Literature reading ten - Detect Rumors on Twitter by Promoting Information Campaigns with Generative Adversarial Learn
MySQL的JSON 数据类型1
Linux系统重启和停止Mysql服务教程
七牛云图片上传
年薪50W+的测试工程师都在用这个:Jmeter 脚本开发之——扩展函数
【3D建模制作技巧分享】ZBrush如何设置笔刷快捷键
3年,从3K涨薪到20k?真是麻雀啄了牛屁股 — 雀食牛逼呀
逆序对的数量
typeScript-部分应用函数
[Cultivation of internal skills of string functions] strcpy + strcat + strcmp (1)
panic: reflect: reflect.Value.SetString using value obtained using unexported field
PZK学C语言之字符串函数(一)
FinClip崁入式搭建生态平台,降低合作门槛
kernel问题定位手段总结
typeScript-promise
【游戏建模模型制作全流程】使用ZBrush制作骷髅王