Framework7 - 选项卡

描述

选项卡是一组按逻辑分组的内容,允许我们在它们之间快速切换,并像手风琴一样节省空间。

选项卡布局

以下代码定义了选项卡的布局 −

<!-- Tabs wrapper, shoud have "tabs" class.It is a required element -->
<div class = "tabs">
   <!-- The tab, should have "tab" class and unique id attribute -->
   
   <!-- The tab is active by default - "active" class -->
   <div class = "tab active" id = "tab1">
      ...  The content for Tab 1 goes here ...
   </div>
   
   <!-- The second tab, should have "tab" class and unique id attribute -->
   <div class = "tab" id = "tab2">
      ... The content for Tab 2 goes here ...
   </div>
</div>

其中 −

  • <div class = "tabs"> − 这是所有选项卡的必需包装器。如果我们错过这一点,选项卡将根本无法工作。

  • <div class = "tab"> − 它是一个单独的选项卡,应该具有 unique id 属性。

  • <div class = "tab active"> −它是一个单独的活动选项卡,使用额外的 active 类使选项卡可见(活动)。

在选项卡之间切换

您可以在选项卡布局中使用一些控制器,以便用户可以在它们之间切换。

为此,您需要创建链接(<a> 选项卡),其 tab-link 类和 href 属性等于目标选项卡的 id 属性 −

<!-- Here the link is used to activates 1st tab, has the same href attribute (#tab1) as the id attribute of 1st tab (tab1)  -->
<a href = "#tab1" class = "tab-link active">Tab 1</a>

<!-- Here the link is used to activates 2st tab, has the same href attribute (#tab2) as the id attribute of 2st tab (tab2)  -->
<a href = "#tab2" class = "tab-link">Tab 2</a>

<a href = "#tab3" class = "tab-link">Tab 3</a>

切换多个选项卡

如果您使用单个选项卡链接在多个选项卡之间切换,则可以使用类,而不是使用 IDdata-tab 属性。

<!-- For Top Tabs  -->
<div class = "tabs tabs-top">
   <div class = "tab tab1 active">...</div>
   <div class = "tab tab2">...</div>
   <div class = "tab tab3">...</div>
</div>

<!-- For Bottom Tabs -->
<div class = "tabs tabs-bottom">
   <div class = "tab tab1 active">...</div>
   <div class = "tab tab2">...</div>
   <div class = "tab tab3">...</div>
</div>

<!-- For Tabs links -->
<div class = "tab-links">
   <!-- Links are switch top and bottom tabs to .tab1 -->
   <a href = "#" class = "tab-link" data-tab = ".tab1">Tab 1</a>
   <!-- Links are switch top and bottom tabs to .tab2 -->
   <a href = "#" class = "tab-link" data-tab = ".tab2">Tab 2</a>
   <!-- Links are switch top and bottom tabs to .tab3 -->
   <a href = "#" class = "tab-link" data-tab = ".tab3">Tab 3</a>
</div>

tab-link 的 data-tab 属性包含目标选项卡的 CSS 选择器。

我们可以使用不同的选项卡方式,这些方式在下表中指定 −

S.No 选项卡类型 &描述
1 内联选项卡

内联选项卡是内联分组的集合,可让您快速在它们之间切换。

2 从导航栏切换选项卡

我们可以在导航栏中放置选项卡,让您可以在它们之间切换。

3 从选项卡栏切换视图

单个选项卡可用于在具有其自己的导航和布局的视图之间切换。

4 动画选项卡

您可以使用简单的过渡(动画)来切换选项卡。

5 可滑动选项卡

您可以使用选项卡的 tabs-swipeable-wrap 类创建具有简单过渡的可滑动选项卡。

6 选项卡 JavaScript 事件

当您使用选项卡的 JavaScript 代码时,可以使用 JavaScript 事件。

7 使用 JavaScript 显示选项卡

您可以使用 JavaScript 方法切换或显示选项卡。