admin管理员组文章数量:1352810
I have a VueJS with bootstrap-vue project. A list of tabs gets rendered but it is larger than the width of the parent. So I want to have a pair of buttons to scroll the list from left to right.
I found this example which I got working in my own project. Horizontal Scroll Using Buttons in VueJS But I can not get it to work with the tabs.
In the methods I target .nav-tabs because that is a class that gets rendered to the DOM. I tried to figure it out with .$refs but could not get to the actual element because that element is only visible once rendered.
Can someone please help to get the tabs scrolling.
/
<div id="app">
<div class="container">
<b-row class="wrap" ref="wrap">
<b-tabs content-class="mt-3">
<b-tab v-for="category in categories" v-bind:title="category.name" :key="category.id">
</b-tab>
<b-tab>
Content
</b-tab>
</b-tabs>
</b-row>
<b-row>
<button @click="scroll_left">Scroll Left</button>
<button @click="scroll_right">Scroll Right</button>
</b-row>
</div>
</div>
methods: {
scroll_left() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft -= 50;
},
scroll_right() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft += 50;
}
.tab-panel {
flex-wrap: nowrap;
}
.wrap {
overflow: hidden;
width: 100%;
flex-direction: row;
}
.nav-tabs {
flex-wrap: nowrap;
white-space: nowrap;
}
I have a VueJS with bootstrap-vue project. A list of tabs gets rendered but it is larger than the width of the parent. So I want to have a pair of buttons to scroll the list from left to right.
I found this example which I got working in my own project. Horizontal Scroll Using Buttons in VueJS But I can not get it to work with the tabs.
In the methods I target .nav-tabs because that is a class that gets rendered to the DOM. I tried to figure it out with .$refs but could not get to the actual element because that element is only visible once rendered.
Can someone please help to get the tabs scrolling.
https://jsfiddle/timmyl/xg8j7knb/19/
<div id="app">
<div class="container">
<b-row class="wrap" ref="wrap">
<b-tabs content-class="mt-3">
<b-tab v-for="category in categories" v-bind:title="category.name" :key="category.id">
</b-tab>
<b-tab>
Content
</b-tab>
</b-tabs>
</b-row>
<b-row>
<button @click="scroll_left">Scroll Left</button>
<button @click="scroll_right">Scroll Right</button>
</b-row>
</div>
</div>
methods: {
scroll_left() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft -= 50;
},
scroll_right() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft += 50;
}
.tab-panel {
flex-wrap: nowrap;
}
.wrap {
overflow: hidden;
width: 100%;
flex-direction: row;
}
.nav-tabs {
flex-wrap: nowrap;
white-space: nowrap;
}
Share
Improve this question
edited Feb 28, 2019 at 17:29
timmy
asked Feb 28, 2019 at 14:53
timmytimmy
4882 gold badges7 silver badges23 bronze badges
1 Answer
Reset to default 8you just need to tweak your css a bit as currently the content of the list is expanding to full screen and you need to add the overflow
property in order the content to be scrollable,
so here what you are missing:
.nav-tabs {
flex-wrap: nowrap;
white-space: nowrap;
max-width: 500px;
overflow: auto;
}
I just modified your sandbox and add the the above property to .nav-tabs
https://jsfiddle/Ljk5a62v/
本文标签: javascriptHow to scroll Tabs in VueJS with BootstrapvueStack Overflow
版权声明:本文标题:javascript - How to scroll Tabs in VueJS with Bootstrap-vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743908083a2559874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论