# Tabby [![Build Status](https://travis-ci.org/cferdinandi/tabby.svg)](https://travis-ci.org/cferdinandi/tabby)
Lightweight, accessible vanilla JS toggle tabs.
**[View the Demo on CodePen →](https://codepen.io/cferdinandi/pen/rRMJwK)**
[Getting Started](#getting-started) | [Styling](#styling-tabby) | [Keyboard Navigation](#keyboard-navigation) | [API](#api) | [What's New](#whats-new) | [Browser Compatibility](#browser-compatibility) | [License](#license)
<hr>
### Want to learn how to write your own vanilla JS plugins? Check out my [Vanilla JS Pocket Guides](https://vanillajsguides.com/) or join the [Vanilla JS Academy](https://vanillajsacademy.com) and level-up as a web developer. ð
<hr>
## Getting Started
Compiled and production-ready code can be found in the `dist` directory. The `src` directory contains development code.
### 1. Include Tabby on your site.
There are two versions of Tabby: the standalone version, and one that comes preloaded with polyfills for the `closest()` and `matches()` methods, which are only supported in newer browsers.
If you're including your own polyfills, use the standalone version. Otherwise, use the version with polyfills.
Tabby also comes with [two simple themes/UIs](#styling-tabby). Feel free to start with one of them and modify it for your needs, or start from scratch and build your own.
**Direct Download**
You can [download the files directly from GitHub](https://github.com/cferdinandi/tabby/archive/master.zip).
```html
<link rel="stylesheet" type="text/css" href="path/to/tabby.min.css">
<script src="path/to/tabby.polyfills.min.js"></script>
```
**CDN**
You can also use the [jsDelivr CDN](https://cdn.jsdelivr.net/gh/cferdinandi/tabby/dist/). I recommend linking to a specific version number or version range to prevent major updates from breaking your site. Tabby uses semantic versioning.
```html
<!-- Always get the latest version -->
<!-- Not recommended for production sites! -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/tabby/dist/css/tabby.min.css">
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/tabby/dist/js/tabby.polyfills.min.js"></script>
<!-- Get minor updates and patch fixes within a major version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/tabby@12/dist/css/tabby.min.css">
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/tabby@12/dist/js/tabby.polyfills.min.js"></script>
<!-- Get patch fixes within a minor version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/css/tabby.min.css">
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/js/tabby.polyfills.min.js"></script>
<!-- Get a specific version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/css/tabby.min.css">
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/js/tabby.polyfills.min.js"></script>
```
**NPM**
You can also use NPM (or your favorite package manager).
```bash
npm install tabbyjs
```
### 2. Add the markup to your HTML.
Tabby progressively enhances a linked list of content into tabbed navigation.
Provide an unordered list of content, with anchor links that point to your content. Give your tab navigation a selector you can target. In this example, it's `[data-tabs]`, but it can be anything you want.
Add the `[data-tabby-default]` attribute to the tab that should be displayed by default.
```html
<ul data-tabs>
<li><a data-tabby-default href="#harry">Harry Potter</a></li>
<li><a href="#hermione">Hermione</a></li>
<li><a href="#neville">Neville</a></li>
</ul>
<div id="harry">...</div>
<div id="hermione">...</div>
<div id="neville">...</div>
```
*__Note:__ Tabby automatically adds all of the required roles, attributes, and keyboard interactions needed for proper accessibility.*
### 3. Initialize Tabby.
In the footer of your page, after the content, initialize Tabby by passing in a selector for the navigation menu. And that's it, you're done. Nice work!
```html
<script>
var tabs = new Tabby('[data-tabs]');
</script>
```
## Styling Tabby
Tabby comes with two simple themes/UIs: standard horizontal tabs, and vertical ones. Use them as-is, modify them to meet your needs, or skip them entirely and build your own from scratch.
**[Horizontal UI on CodePen →](https://codepen.io/cferdinandi/pen/rRMJwK)** | **[Veritical UI on CodePen →](https://codepen.io/cferdinandi/pen/WmGMgZ)** | **[No UI on CodePen →](https://codepen.io/cferdinandi/pen/LaRdbG)**
*__Note:__ the vertical tab layout does not include a grid. You'll need to supply your own.*
You can use the `role` attributes that are added to the elements to progressively style them.
- The list (`<ul></ul>`) has the `[role="tablist"]` attribute.
- Tab links (`<a href="#anchor"></a>`) have the `[role="tab"]` attribute.
- Active tab links have the `[aria-selected="true"]` attribute.
- Tab content has the `[role="tabpanel"]` attribute.
- Hidden tab content has the `[hidden]` attribute.
## Keyboard Navigation
Tabby follows [accessibility recommendations and expectations for keyboard navigation](https://davatron5000.github.io/a11y-nutrition-cards/#tabs):
- Arrow keys (left/right and up/down) change the active tab in the navigation.
- The `Home` and `End` buttons activate the first and last tab, respectively.
- The `Tab` key shifts focus *into the tab content* rather than to the next item in the navigation.
## API
Tabby includes smart defaults and works right out of the box. But if you want to customize things, it also has a robust API that provides multiple ways for you to adjust the default options and settings.
### Options and Settings
You can pass options and callbacks into Tabby when instantiating.
```javascript
var tabs = new Tabby('[data-tabs]', {
idPrefix: 'tabby-toggle_', // The prefix to add to tab element IDs if they don't already have one
default: '[data-tabby-default]' // The selector to use for the default tab
});
```
### Custom Events
Tabby emits a custom event—`tabby`—when the active tab is changed.
The `tabby` event is emitted on the tab element and bubbles up. You can listen for them with the `addEventListener()` method. The `event.detail` object includes the `previousTab`, `previousContent`, `tab` and `content` elements.
```js
document.addEventListener('tabby', function (event) {
var tab = event.target;
var content = event.detail.content;
}, false);
```
### Methods
Tabby also exposes several public methods.
#### setup()
Sets up the DOM with the required roles and attributes. If you dynamically add navigation items to the DOM after Tabby is instantiated, you can run this method to set them up.
**Example**
```javascript
var tabs = new Tabby('data-tabs');
tabs.setup();
```
#### toggle()
Activate a tab. Accepts the ID of the content to activate, *or* a tab element, as an argument.
**Example**
```javascript
var tabs = new Tabby('data-tabs');
// With a selector
tabs.toggle('#harry');
// With an element
var neville = document.querySelector('[href*="#neville"]');
tabs.toggle(neville);
```
#### destroy()
Destroy the current initialization.
**Example**
```javascript
var tabs = new Tabby('data-tabs');
tabs.destroy();
```
## What's new?
Tabby got a complete rewrite in version 12. It now includes:
- Support for multiple instantiations at once.
- Proper roles and properties for accessibility.
- Keyboard navigation
- Deprecated callbacks in favor of custom events.
### Migrating to Tabby 12 from Older Versions
The instantiation method is completely different, but the markup patterns in older versions should work without modification.
## Kudos ð
Special thanks to [Dave Rupers A11y Nutrition Cards](https://davatron5000.github.io/a11y-nutrition-cards/#tabs), which provided a solid foundation for this version.
And major kudos to [accessibility
没有合适的资源?快使用搜索试试~ 我知道了~
【WordPress插件】2022年最新版完整功能demo+插件v2.1.6.zip
共738个文件
php:382个
js:158个
css:63个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 106 浏览量
2022-04-09
06:51:22
上传
评论
收藏 2.09MB ZIP 举报
温馨提示
"【WordPress插件】2022年最新版完整功能demo+插件v2.1.6 Agency Base For Oxygen Builder 氧气建设者的代理基础" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,更有超10000个资源可供选择,如有需要请站内联系。
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress插件】2022年最新版完整功能demo+插件v2.1.6.zip (738个子文件)
.babelrc 146B
date.css 25KB
jquery.ui.theme.css 17KB
select2.css 17KB
ab-oxy-ui.css 6KB
tabs.css 5KB
group.css 5KB
jquery.ui.datepicker.css 4KB
style.css 3KB
settings.css 3KB
switch.css 2KB
about.css 2KB
button-group.css 2KB
jquery-ui-timepicker-addon.min.css 2KB
user-profile.css 2KB
term-meta.css 2KB
demo.css 2KB
pushbar.css 2KB
columns.css 1KB
tabby-ui.css 1KB
user-meta.css 1KB
user-meta.css 1KB
jquery.ui.core.css 1KB
image.css 1KB
jquery.ui.slider.css 1KB
form.css 1KB
map.css 1KB
osm.css 1KB
tabby-ui.min.css 941B
customizer.css 917B
dashboard.css 876B
tabby-ui-vertical.css 841B
media.css 793B
input.css 750B
tabby.css 743B
file.css 741B
select-advanced.css 655B
admin-columns.css 644B
tabby-ui-vertical.min.css 487B
custom.css 436B
text-list.css 427B
background.css 413B
input-list.css 407B
admin-ui-additions.css 405B
image-select.css 376B
tabby.min.css 370B
video.css 343B
file-input.css 326B
tooltip.css 319B
taxonomy.css 312B
heading.css 303B
upload.css 292B
autocomplete.css 285B
slider.css 255B
text-limiter.css 196B
select.css 192B
wysiwyg.css 189B
oembed.css 181B
divider.css 174B
color.css 162B
style-rtl.css 154B
range.css 146B
select-tree.css 92B
fieldset-text.css 84B
.DS_Store 6KB
.editorconfig 465B
.editorconfig 465B
.editorconfig 465B
.editorconfig 465B
animated.pushbar.js.gif 1.2MB
drag_icon.gif 106B
.gitattributes 48B
index.html 7KB
index.html 2KB
vertical.html 2KB
vertical.html 2KB
index.html 2KB
index.html 2KB
bare.html 2KB
bare.html 2KB
multiple.html 855B
constructor-nodelist.html 826B
contenteditable.html 824B
constructor-selector.html 806B
function-target.html 743B
nested.html 737B
constructor-node.html 736B
target-input.html 726B
target-textarea.html 720B
undelegate.html 715B
multiple.html 713B
function-text.html 709B
dropdown.html 708B
multiple.html 705B
target-div.html 697B
delegate.html 663B
editable.html 607B
destroy.html 590B
non-editable.html 578B
nodelist.html 560B
共 738 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
Lee达森
- 粉丝: 966
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功