实现简单的竖向tab

6 篇文章 0 订阅

项目中需要用到竖版的Tab,但是用的框架没有合适的,所以没办法,只能自己写了,希望能帮助到其他人。写的比较简单,只符合自己使用的效果,大神勿喷。

效果是这种的:标签数量很多,超出部分可以点击上下的icon切换滚动,用的是vue和iviewUI的icon实现的



< template >
< div class= "tabWrap" >
< div class= "tabNav" >
< span class= "iconClass" >
< Icon type= "chevron-up" @click.native=" upTab" ></ Icon >
</ span >
< div id= "tabBar" >
< ul id= "tabUl" >
< li :class="[{ activeTab:index === tabIndex}, 'tabLi']" v-for="( item, index) in tabList" :key=" index"
@click=" changeTab( index)" >{{ item. label}} </ li >
</ ul >
</ div >
< span class= "iconClass" >
< Icon type= "chevron-down" @click.native=" downTab" ></ Icon >
</ span >
</ div >
< div class= "tabContent" >
< div v-if="tabIndex === 0" >content内容 </ div >
</ div >
</ div >
</ div >
</ template >

< script >
watch: {
tabIndex: function ( newVal) {
this. imgShow = 0
let scrollNav = document. getElementById( 'tabUl')
let tabBar = document. getElementById( 'tabBar')
let transformHeight = scrollNav. scrollHeight - tabBar. clientHeight
if ( Number( newVal) >= 3) {
this. $nextTick( function () {
scrollNav. style. transform = `translateY(- ${ transformHeight } px)`
})
} else {
this. $nextTick( function () {
scrollNav. style. transform = 'translateY(0px)'
})
}
}
},

data () {
return {
tabIndex: 0,
tabList: [
{ label: 'tab1'},
],

}
},

methods: {
// 更改tab页签
changeTab ( index) {
this. tabIndex = index
this. $store. state. proofActiveName = this. tabIndex
this. imgShow = 0
},
// 调整Tab滚动
upTab () {
let scrollNav = document. getElementById( 'tabUl')
this. $nextTick( function () {
scrollNav. style. transform = 'translateY(0px)'
})
},
downTab () {
let scrollNav = document. getElementById( 'tabUl')
let tabBar = document. getElementById( 'tabBar')
let transformHeight = scrollNav. scrollHeight - tabBar. clientHeight
this. $nextTick( function () {
scrollNav. style. transform = `translateY(- ${ transformHeight } px)`
})
}
}


</ script >

< style lang= "less" >
.tabWrap{
width: 100%;
height: 100%;
.tabNav{
width: 40px;
height: 100%;
float: left;
#tabBar{
height: e( "calc(100% - 60px)");
overflow: hidden;
z-index: -1;
#tabUl{
width: 34px;
margin-left: 6px;
border-right: 1px solid #dddee1;
transition: -webkit-transform .5s ease-in-out;
transition: transform .5s ease-in-out;
.tabLi{
width: 100%;
font-size: 14px;
writing-mode: vertical-lr;
padding: 14px 0 14px 5px;
cursor: pointer;
border: 1px solid #dddee1;
border-right: 0;
margin-bottom: 5px;
border-radius: 5px 0 0 6px;
text-align: center;
vertical-align: middle;
background: #f8f8f9;
}
.tabLi:hover{
color: #2d8cf0;
}
.activeTab{
color: #2d8cf0;
background: #ffffff;
width: 36px;
z-index: 100;
}
}
}
.iconClass{
display: inline-block;
height: 30px;
margin-left: 8px;
cursor: pointer;
text-align: center;
line-height: 30px;
width: e( "calc(100% - 10px)");
}
}
.tabContent{
float: left;
background: #fff;
width: e( "calc(100% - 41px)");
height: 100%;
overflow: auto;
}
}
</ style >

有哪个大神有更好的实现方式 可以评论分享,多指教~~

Bootstrap是一个流行的前端开发框架,它提供了丰富的组件和样式,可以帮助开发者快速构建响应式网页。在Bootstrap中,Tab切换是一种常见的交互方式,可以让用户在不同的选项卡之间进行切换。 要实现竖向Tab切换,可以借助Bootstrap的Navs组件和Tabs组件。下面是一个简单的示例代码: ```html <div class="container"> <div class="row"> <div class="col-md-3"> <ul class="nav nav-pills flex-column" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link active" id="tab1-tab" data-toggle="tab" href="#tab1" role="tab" aria-controls="tab1" aria-selected="true">Tab 1</a> </li> <li class="nav-item"> <a class="nav-link" id="tab2-tab" data-toggle="tab" href="#tab2" role="tab" aria-controls="tab2" aria-selected="false">Tab 2</a> </li> <li class="nav-item"> <a class="nav-link" id="tab3-tab" data-toggle="tab" href="#tab3" role="tab" aria-controls="tab3" aria-selected="false">Tab 3</a> </li> </ul> </div> <div class="col-md-9"> <div class="tab-content" id="myTabContent"> <div class="tab-pane fade show active" id="tab1" role="tabpanel" aria-labelledby="tab1-tab"> Content for Tab 1 </div> <div class="tab-pane fade" id="tab2" role="tabpanel" aria-labelledby="tab2-tab"> Content for Tab 2 </div> <div class="tab-pane fade" id="tab3" role="tabpanel" aria-labelledby="tab3-tab"> Content for Tab 3 </div> </div> </div> </div> </div> ``` 在上面的代码中,我们使用了`nav`和`tab-content`两个组件来实现Tab切换。`nav`组件用于显示选项卡,`tab-content`组件用于显示对应选项卡的内容。 首先,我们创建一个具有`flex-column`类的`ul`元素,这样可以使选项卡垂直排列。每个选项卡都是一个`li`元素,其中的`a`元素用于触发切换。通过设置`data-toggle="tab"`属性和`href`属性来关联选项卡和对应的内容。 然后,我们创建一个具有`tab-content`类的`div`元素,其中的每个子元素都是一个选项卡的内容。通过设置`id`属性和`aria-labelledby`属性来关联内容和对应的选项卡。 最后,我们使用Bootstrap提供的CSS类来设置选项卡和内容的样式,例如使用`active`类来标记默认显示的选项卡。 通过以上代码,我们就可以实现一个简单竖向Tab切换效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值