Tabbed Content With Equal Height Support – sv-tabs-js

Category: Javascript | March 2, 2021
Author: svivian
Views Total: 103 views
Official Page: Go to website
Last Update: March 2, 2021
License: MIT

Preview:

Tabbed Content With Equal Height Support – sv-tabs-js

Description:

A tiny tabs JavaScript library that helps create tabbed content with equal height support.

The library automatically adjusts the height of the tabs component based on the tallest tabbed content.

Also provides a functionality to automatically update hashtag in the URL, which means that the users are able to open specific tabbed content by URL.

How to use it:

1. Insert the sv-tabs-js’ JavaScript and CSS files into the document.

<link rel="stylesheet" href="sv-tabs.css" />
<script src="sv-tabs.js"></script>

2. The required HTML structure for the tabs & tabbed content.

<div class="sv-tabs-wrapper">
  <nav class="sv-tabs-tab-list">
    <a class="sv-tabs-tab active" href="#tab1">Tab 1</a>
    <a class="sv-tabs-tab" href="#tab2">Tab 2: Tab Harder</a>
    <a class="sv-tabs-tab" href="#tab3">3</a>
  </nav>
  <div class="sv-tabs-panel-list">
    <div class="sv-tabs-panel" id="tab2">
      I'll be whatever I wanna do.
    </div>
    <div class="sv-tabs-panel" id="tab3">
      Interesting. No, wait, the other thing: tedious. Shut up and take my money! OK, if everyone's finished being stupid. And I'd do it again! And perhaps a third time! But that would be it. Throw her in the brig. I'm just glad my fat, ugly mama isn't alive to see this day. File not found. Ah, the 'Breakfast Club' soundtrack! I can't wait til I'm old enough to feel ways about stuff.
    </div>
    <div class="sv-tabs-panel active" id="tab1">
      You may have to metaphorically make a deal with the devil. And by "devil", I mean Robot Devil. And by "metaphorically", I mean get your coat.
    </div>
  </div>
</div>

3. Initialize the tabs component.

var tabWrapper = document.querySelector('.sv-tabs-wrapper');
var svTabs = new SV.Tabs(tabWrapper);

4. Determine whether the equalize the height of the tabbed content. Default: false.

var svTabs = new SV.Tabs(tabWrapper,{
    equalHeight: true
});

5. Determine whether to add anchor links to tabs. Default: false.

var svTabs = new SV.Tabs(tabWrapper,{
    useAnchors: true
});

6. Override the default variables to create your own styles.

// Compile with `sass sv-tabs.scss:sv-tabs.css --no-source-map`
$spacing-unit: 16px !default;
$base-border: 1px solid #ccc !default;
$bd-rad: 4px !default;

$tab-bg-on: #fff !default;
$tab-bg-off: #eee !default;
$tab-bg-hover: #ddd !default;

$tab-text-on: #666 !default;
$tab-text-off: #666 !default;

You Might Be Interested In:


Leave a Reply