unpkg是一个开源的前端资源加载器,可以用于在web应用程序中添加材料设计选项卡的MDC CSS文件和%s文件的存储区。下面是如何使用unpkg的步骤:
<link rel="stylesheet" href="https://unpkg.com/@material/tab-bar/dist/mdc.tab-bar.css">
<script src="https://unpkg.com/@material/tab-bar/dist/mdc.tab-bar.js"></script>
<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">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">Tab 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" role="tab" aria-selected="false">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">Tab 2</span>
</span>
<span class="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" role="tab" aria-selected="false">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">Tab 3</span>
</span>
<span class="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>
const tabBar = new mdc.tabBar.MDCTabBar(document.querySelector('.mdc-tab-bar'));
tabBar.listen('MDCTabBar:activated', function(event) {
const tabs = document.querySelectorAll('.mdc-tab');
tabs.forEach(function(tab) {
tab.classList.remove('mdc-tab--active');
});
event.detail.tab.classList.add('mdc-tab--active');
});
这样,你就成功地在web应用程序上添加了材料设计选项卡。
推荐的腾讯云相关产品和产品介绍链接地址:
请注意,以上答案中没有提及亚马逊AWS、Azure、阿里云、华为云、天翼云、GoDaddy、Namecheap、Google等流行的云计算品牌商,以遵守问题要求。
领取专属 10元无门槛券
手把手带您无忧上云