当前位置:网站首页>uniapp动态实现滑动导航效果demo(整理)
uniapp动态实现滑动导航效果demo(整理)
2022-08-04 23:15:00 【我是开心呀】
效果图:
<template>
<view class="content">
<!-- 导航区域 -->
<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="0" enable-flex="true">
<view :class="['scroll-view-item_H',currentTab==index?'active':'']" v-for="(item,index) in navbar"
:key='index' @click="tabClick(index)">{
{
item}}</view>
</scroll-view>
<!-- 内容区域 -->
<swiper class="swiper" :current="currentTab" @change="swiperTab" :style="{height:swiperHeight+'px'}">
<swiper-item>
<view class="swiper-item">
导航一内容导航一内容导航一内容导航一内容
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
导航二内容导航二内容导航二内容导航二内容
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
导航三内容导航三内容导航三内容导航三内容
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
导航四内容导航四内容导航四内容导航四内容
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
navbar: ['导航一', '导航二', '导航三', '导航四'], //导航栏类目
currentTab: 0, //当前选中的导航类目
swiperHeight: 0 //动态给定swiper的高度
}
},
onLoad(option) {
this.swiperHeight = uni.getSystemInfoSync().windowHeight - 25;
console.log(this.swiperHeight);
},
methods: {
tabClick(index) {
this.currentTab = index
},
swiperTab(e) {
this.currentTab = e.detail.current; //获取索引
console.log("this.currentTab", this.currentTab)
}
}
}
</script>
<style lang="less" scoped>
.content {
width: 100%;
.scroll-view_H {
width: 100%;
height: 60rpx;
text-align: center;
line-height: 60rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
overflow: hidden;
.scroll-view-item_H {
flex-shrink: 0;
width: 300rpx;
color: #000000;
font-size: 30rpx;
font-size: bold;
background-color: #EA5149;
letter-spacing: .1em;
text-shadow: 0px 1px 2px #A42B14;
}
.active {
font-size: 40rpx;
color: #55aaff;
}
}
.swiper-item {
height: 100%;
}
}
</style>
边栏推荐
猜你喜欢
随机推荐
【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
吐槽 | 参加IT培训的正确姿势
[QNX Hypervisor 2.2用户手册]10.5 vdev ioapic
956. 最高的广告牌
【软件测试】常用ADB命令
使用OpenCV实现一个文档自动扫描仪
web3.js
Nacos配置中心之客户端长轮询
kernel hung_task死锁检测机制原理实现
[Cultivation of internal skills of string functions] strlen + strstr + strtok + strerror (3)
养殖虚拟仿真软件提供高沉浸式的虚拟场景互动操作体验学习
【内存操作函数内功修炼】memcpy + memmove + memcmp + memset(四)
postman接口测试
Kernel函数解析之kernel_restart
407. 接雨水 II
Service Mesh landing path
[Cultivation of internal skills of string functions] strncpy + strncat + strncmp (2)
To Offer | 03. Repeat Numbers in the array
话题 | 雾计算和边缘计算有什么区别?
Shell expect 实战案例