gpt4 book ai didi

javascript - Material.io 标签 : where to put the tab content?

转载 作者:行者123 更新时间:2023-12-05 05:57:58 25 4
gpt4 key购买 nike

我正在尝试在元素中使用 material.io 选项卡,无论如何 html 结构没有很好的记录:

https://material.io/components/tabs/web#design-api-documentation

<div class="mdc-tab-bar" role="tablist">
<div class="mdc-tab-scroller">
<div class="mdc-tab-scroller__scroll-area">
<div class="mdc-tab-scroller__scroll-content">
<button class="mdc-tab mdc-tab--active" role="tab" aria-selected="true" tabindex="0">
<span class="mdc-tab__content">
<span class="mdc-tab__icon material-icons" aria-hidden="true">favorite</span>
<span class="mdc-tab__text-label">Favorites</span>
</span>
<span class="mdc-tab-indicator mdc-tab-indicator--active">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
</button>
</div>
</div>
</div>
</div>

我应该把标签正文内容放在哪里?他们似乎只展示了如何构建标签栏,但没有展示全部功能?

最佳答案

首先,您应该在一个 div 中制作标签栏,然后在另一个 div 中制作内容,另外使用 javascript 来指定何时更改内容。我希望这个答案有所帮助。我想我的答案一定不是很清楚,但是当你浏览代码时你会发现我的意思

<div class="svelte4" style="flex:1;" id="tim">
<div class="mdc-tab-bar" role="tablist" style="background-color:rgb(34, 34, 34);">
<div class="mdc-tab-scroller">
<div class="mdc-tab-scroller__scroll-area">
<div class="mdc-tab-scroller__scroll-content">

<button class="mdc-tab mdc-tab--active" role="tab" aria-selected="true" tabindex="0">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">1</span>
</span>
<span class="mdc-tab-indicator mdc-tab-indicator--active">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
</button>



<button class="mdc-tab mdc-tab" role="tab" aria-selected="true" tabindex="0">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">2</span>
</span>
<span class="mdc-tab-indicator mdc-tab-indicator">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
</button>


<button class="mdc-tab mdc-tab" role="tab" aria-selected="true" tabindex="0">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">3</span>
</span>
<span class="mdc-tab-indicator mdc-tab-indicator">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
</button>






</div>
</div>
</div>

</div>


<div class="content content--active">
<p>1</p>
</div>

<div class="content">
<p>2</p>
</div>

<div class="content">
<p>3</p>
</div>
</div>
var tabBar = new mdc.tabBar.MDCTabBar(document.querySelector('.mdc-tab-bar'));
var contentEls = document.querySelectorAll('.content');

tabBar.listen('MDCTabBar:activated', function (event) {
// Hide currently-active content
document.querySelector('.content--active').classList.remove('content--active');
// Show content for newly-activated tab
contentEls[event.detail.index].classList.add('content--active');
});

关于javascript - Material.io 标签 : where to put the tab content?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68649454/

25 4 0