Simple Tabs by Alexander Sharkov
v.1.1.2
What's new
- Added tabButtonTitleAttribute for automatically creates tabs link buttons.
- Fixed issue including list items into tabs content.
v.1.1.1
What's new
- Add callbacks
- Add online Demo
v.1.1.0
What's new
- Add new options
- Cleared js code
- Add lad html data in content using ajax (How to use)
Demo
1.Getting Started
- Download source
If you use Bower
bower install SimpleTabs -save
If you use NPM
npm install simpletabs
- Load jQuery(1.7+)
- Include source files of SimpleTabs into your project
- And read this manual to include tabs to your project
Html to head
<!-- Important include --><!-- /Important include --><!-- You can include or write your own stylesheet --><!-- /You can include or write your own stylesheet -->
Html before close body
2.Set up your HTML
You need insert my html example. And all you need add your id to container of tabs.
Html
<!-- Simple tabs --> <!-- Simple tabs buttons --> Tab 1 Tab 2 Tab 3 <!-- /Simple tabs buttons --> <!-- Simple tabs contents --> <!-- Simple tabs content item --> Tab content <!-- /Simple tabs content item --> <!-- Simple tabs content item --> Tab content <!-- /Simple tabs content item --> <!-- Simple tabs content item --> Tab content <!-- /Simple tabs content item --> <!-- Simple tabs contents --><!-- /Simple tabs -->
3.Call the plugin
Now call the SimpleTabs initializer function, and your tabs are ready.
JavaScript
;
Or you can set call initializer function to ID container. And you can use tabs options to initializations tabs.
Example a call to initializations of tabs with all options:
JavaScript
;
4.Options list
Main options
Option | Type | Default | Description |
---|---|---|---|
start | number | 1 | You could select a number of the tab, and it will open, after a page has loaded. if you write a value of 0, not one tab will open. |
vertical | boolean | false | Options need to select what type the tabs will be. If you write true, than script will add verticalClass to container of tabs, else script will add horizontalClass |
mainClass | string | "simple_tabs" | Class name for container of tabs |
verticalClass | string | "simple_tabs_vertical" | Class name for container of tabs, when vertical option is true. |
horizontalClass | string | "simple_tabs_horizontal" | Class name for container of tabs, when vertical option is false. |
tabIdSuffix | string | "-tab-" | suffix is necessary to create ids for the content items and links in the tabs. |
tabActiveClass | string | "active" | Class name for the active tab. |
ajaxMessageError | string | "Sorry! No data to load :(" | Text of message, when ajax can't load data. |
buttons | object | {...} | Option contains a object with several options. Look options list in Buttons options table |
content | object | {...} | Option contains a object with several options. Look options list in Content options table |
callbacks | object | {...} | Option contains a object with several options. Look options list in Callbacks options table |
Buttons options
Option | Type | Default | Description |
---|---|---|---|
containerElement | string | "ul" | Tag name for container to links of tabs. |
containerClass | string | "tabs_buttons" | Class name for container to links of tabs. |
itemElement | string | "li" | Tag name for items to links of tabs. |
itemClass | string | "tab_button_wrapper" | Class name for items to links of tabs. |
linkElement | string | "a" | Tag name for links of tabs. |
linkClass | string | "tab_button" | Class name for links of tabs. |
Content options
Option | Type | Default | Description |
---|---|---|---|
containerClass | string | "tabs_contents" | Class name for container of content of tabs. |
itemElement | string | "div" | Tag name for an item of container of content of tabs. |
itemClass | string | "tab_content" | Class name for an item of container of content of tabs. |
tabButtonTitleAttribute | string | "data-tab-title" | Attribute name with tab links text for creation tab buttons automatically. |
Callbacks options
Option | Type | Default | Description |
---|---|---|---|
callBeforeChange | function | null | Give to you options to change other scripts or DOM elements before that a current tab will change to new. |
callAfterChange | function | null | Give to you options to change other scripts or DOM elements after that a current tab changed to new. |
Example, how to use callbacks:
JavaScript
;
5.Use Ajax
To use this function, You need add the data-ajax attribute with link to data in tag for links of tabs.
Example how to use ajax loading for data:
Html
<!-- Simple tabs --> <!-- Simple tabs buttons --> Tab 1 Tab 2 Tab 3 <!-- /Simple tabs buttons --> <!-- Simple tabs contents --> <!-- Simple tabs contents --><!-- /Simple tabs -->
JavaScript
;
Notes
One interesting moment about my tabs. You can insert any content, in button of tab, or content item of tab. You can create your own stylesheets for it. Special for you, I inserted to project scss files that you can use to create your own themes for SimpleTabs.