tim*_*mmy 2 javascript bootstrap-4 vuejs2 bootstrap-vue
我有一个带有 bootstrap-vue 项目的 VueJS。一个选项卡列表被渲染,但它大于父级的宽度。所以我想要一对按钮从左到右滚动列表。
我找到了这个例子,我在自己的项目中工作。 在 VueJS 中使用按钮进行水平滚动 但我无法让它与选项卡一起使用。
在我针对 .nav-tabs 的方法中,因为这是一个呈现给 DOM 的类。我试图用 .$refs 找出它,但无法到达实际元素,因为该元素仅在渲染后可见。
有人可以帮助让标签滚动。
https://jsfiddle.net/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>
Run Code Online (Sandbox Code Playgroud)
methods: {
scroll_left() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft -= 50;
},
scroll_right() {
let content = document.querySelector(".nav-tabs");
content.scrollLeft += 50;
}
Run Code Online (Sandbox Code Playgroud)
.tab-panel {
flex-wrap: nowrap;
}
.wrap {
overflow: hidden;
width: 100%;
flex-direction: row;
}
.nav-tabs {
flex-wrap: nowrap;
white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)
您只需要稍微调整一下您的 css,因为当前列表的内容正在扩展到全屏,并且您需要添加该overflow属性以使内容可滚动,
所以在这里你缺少什么:
.nav-tabs {
flex-wrap: nowrap;
white-space: nowrap;
max-width: 500px;
overflow: auto;
}
Run Code Online (Sandbox Code Playgroud)
我刚刚修改了您的沙箱并将上述属性添加到 .nav-tabs
https://jsfiddle.net/Ljk5a62v/
| 归档时间: |
|
| 查看次数: |
5915 次 |
| 最近记录: |