// Easy Responsive Tabs Plugin
// Author: Samson.Onna <Email : [email protected]>
(function ($) {
$.fn.extend({
easyResponsiveTabs: function (options) {
//Set the default values, use comma to separate the settings, example:
var defaults = {
type: 'default', //default, vertical, accordion;
width: 'auto',
fit: true
}
//Variables
var options = $.extend(defaults, options);
var opt = options, jtype = opt.type, jfit = opt.fit, jwidth = opt.width, vtabs = 'vertical', accord = 'accordion';
//Main function
this.each(function () {
var $respTabs = $(this);
$respTabs.find('ul.resp-tabs-list li').addClass('resp-tab-item');
$respTabs.css({
'display': 'block',
'width': jwidth
});
$respTabs.find('.resp-tabs-container > div').addClass('resp-tab-content');
jtab_options();
//Properties Function
function jtab_options() {
if (jtype == vtabs) {
$respTabs.addClass('resp-vtabs');
}
if (jfit == true) {
$respTabs.css({ width: '100%', margin: '0px' });
}
if (jtype == accord) {
$respTabs.addClass('resp-easy-accordion');
$respTabs.find('.resp-tabs-list').css('display', 'none');
}
}
//Assigning the h2 markup
var $tabItemh2;
$respTabs.find('.resp-tab-content').before("<h2 class='resp-accordion' role='tab'><span class='resp-arrow'></span></h2>");
var itemCount = 0;
$respTabs.find('.resp-accordion').each(function () {
$tabItemh2 = $(this);
var innertext = $respTabs.find('.resp-tab-item:eq(' + itemCount + ')').text();
$respTabs.find('.resp-accordion:eq(' + itemCount + ')').append(innertext);
$tabItemh2.attr('aria-controls', 'tab_item-' + (itemCount));
itemCount++;
});
//Assigning the 'aria-controls' to Tab items
var count = 0,
$tabContent;
$respTabs.find('.resp-tab-item').each(function () {
$tabItem = $(this);
$tabItem.attr('aria-controls', 'tab_item-' + (count));
$tabItem.attr('role', 'tab');
//First active tab
$respTabs.find('.resp-tab-item').first().addClass('resp-tab-active');
$respTabs.find('.resp-accordion').first().addClass('resp-tab-active');
$respTabs.find('.resp-tab-content').first().addClass('resp-tab-content-active').attr('style', 'display:block');
//Assigning the 'aria-labelledby' attr to tab-content
var tabcount = 0;
$respTabs.find('.resp-tab-content').each(function () {
$tabContent = $(this);
$tabContent.attr('aria-labelledby', 'tab_item-' + (tabcount));
tabcount++;
});
count++;
});
//Tab Click action function
$respTabs.find("[role=tab]").each(function () {
var $currentTab = $(this);
$currentTab.click(function () {
var $tabAria = $currentTab.attr('aria-controls');
if ($currentTab.hasClass('resp-accordion') && $currentTab.hasClass('resp-tab-active')) {
$respTabs.find('.resp-tab-content-active').slideUp('', function () { $(this).addClass('resp-accordion-closed'); });
$currentTab.removeClass('resp-tab-active');
return false;
}
if (!$currentTab.hasClass('resp-tab-active') && $currentTab.hasClass('resp-accordion')) {
$respTabs.find('.resp-tab-active').removeClass('resp-tab-active');
$respTabs.find('.resp-tab-content-active').slideUp().removeClass('resp-tab-content-active resp-accordion-closed');
$respTabs.find("[aria-controls=" + $tabAria + "]").addClass('resp-tab-active');
$respTabs.find('.resp-tab-content[aria-labelledby = ' + $tabAria + ']').slideDown().addClass('resp-tab-content-active');
} else {
$respTabs.find('.resp-tab-active').removeClass('resp-tab-active');
$respTabs.find('.resp-tab-content-active').removeAttr('style').removeClass('resp-tab-content-active').removeClass('resp-accordion-closed');
$respTabs.find("[aria-controls=" + $tabAria + "]").addClass('resp-tab-active');
$respTabs.find('.resp-tab-content[aria-labelledby = ' + $tabAria + ']').addClass('resp-tab-content-active').attr('style', 'display:block');
}
});
//Window resize function
$(window).resize(function () {
$respTabs.find('.resp-accordion-closed').removeAttr('style');
});
});
});
}
});
})(jQuery);
$(document).ready(function () {
$('#horizontalTab').easyResponsiveTabs({
type: 'default', //Types: default, vertical, accordion
width: 'auto', //auto or any width like 600px
fit: true // 100% fit in a container
});
$('#verticalTab').easyResponsiveTabs({
type: 'vertical',
width: 'auto',
fit: true
});
});
body {
margin: 0px;
padding: 0px;
background: #f5f5f5;
font-family: 'Segoe UI';
}
ul.resp-tabs-list, p {
margin: 0px;
padding: 0px;
}
.resp-tabs-list li {
font-weight: 600;
font-size: 13px;
display: inline-block;
padding: 13px 15px;
margin: 0;
list-style: none;
cursor: pointer;
float: left;
}
.resp-tabs-container {
padding: 0px;
background-color: #fff;
clear: left;
}
h2.resp-accordion {
cursor: pointer;
padding: 5px;
display: none;
}
.resp-tab-content {
display: none;
padding: 15px;
}
.resp-tab-active {
border: 1px solid #c1c1c1;
border-bottom: none;
margin-bottom: -1px !important;
padding: 12px 14px 14px 14px !important;
}
.resp-tab-active {
border-bottom: none;
background-color: #fff;
}
.resp-content-active, .resp-accordion-active {
display: block;
}
.resp-tab-content {
border: 1px solid #c1c1c1;
}
h2.resp-accordion {
font-size: 13px;
border: 1px solid #c1c1c1;
border-top: 0px solid #c1c1c1;
margin: 0px;
padding: 10px 15px;
}
h2.resp-tab-active {
border-bottom: 0px solid #c1c1c1 !important;
margin-bottom: 0px !important;
padding: 10px 15px !important;
}
h2.resp-tab-title:last-child {
border-bottom: 12px solid #c1c1c1 !important;
background: blue;
}
/*-----------Vertical tabs-----------*/
.resp-vtabs ul.resp-tabs-list {
float: left;
width: 30%;
}
.resp-vtabs .resp-tabs-list li {
display: block;
padding: 15px 15px !important;
margin: 0;
cursor: pointer;
float: none;
}
.resp-vtabs .resp-tabs-container {
padding: 0px;
background-color: #fff;
border: 1px solid #c1c1c1;
float: left;
width: 68%;
min-height: 250px;
border-radius: 4px;
clear: none;
}
.resp-vtabs .resp-tab-content {
border: none;
}
.resp-vtabs li.resp-tab-active {
border: 1px solid #c1c1c1;
border-right: none;
background-color: #fff;
position: relative;
z-index: 1;
margin-right: -1px !important;
padding: 14px 15px 15px 14px !important;
}
.resp-arrow {
width: 0;
height: 0;
float: right;
margin-top: 3px;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-top: 12px solid #c1c1c1;
}
h2.resp-tab-active span.resp-arrow {
border: none;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 12px solid #9B9797;
}
/*-----------Accordion styles-----------*/
h2.resp-tab-active {
background: #DBDBDB !important;
}
.resp-easy-accordion h2.resp-accordion {
display: block;
}
.resp-easy-accordion .resp-tab-content {
border: 1px solid #c1c1c1;
}
.resp-easy-accordion .resp-tab-content:last-child {
border-bottom: 1px solid #c1c1c1 !important;
}
.resp-jfit {
width: 100%;
margin: 0px;
}
.resp-tab-content-active {
display: block;
}
h2.resp-accordion:first-child {
border-top: 1px solid #c1c1c1 !important;
}
/*Here your can change the breakpoint to set the accordion, when screen resolution changed*/
@media only screen and (max-width: 768px) {
ul.resp-tabs-list {
display: none;
}
h2.resp-accordion {
display: block;
}
.resp-vtabs .resp-tab-content {
border: 1px solid #C1C1C1;
}
.resp-vtabs .resp-tabs-container {
border: none;
float: none;
width: 100%;
min-height: initial;
clear: none;
}
.resp-accordion-closed {
display:none !important;
}
.resp-vtabs .resp-tab-content:last-child {
border-bottom: 1px solid #c1c1c1 !important;
}
}
<div id="horizontalTab">
<ul class="resp-tabs-list">
<li>東京</li>
<li>山形</li>
<li>沖縄</li>
</ul>
<div class="resp-tabs-container">
<div>
<p>2012年現在、国際連合の統計によると、東京は世界最大のメガシティと評価されており、川崎、横浜などとともに世界最大の人口を有する都市圏を形成している。都市単位の経済規模(GDP)ではニューヨークをしのぎ、世界最大である。2012年、アメリカのシンクタンクが公表したビジネス・人材・文化・政治などを対象とした総合的な世界都市ランキングにおいて、ニューヨーク、ロンドン、パリに次ぐ世界第4位の都市と評価された。</p>
</div>
<div>
<p>県域を地図で見ると人間の顔の形(西向きの横顔)をしている。県の東側一帯で宮城県との境に奥羽山脈、県の西部に朝日連峰がそびえているように、県域の大半 (85%) を山地が占め、総面積に対する森林の割合は 75% 、農業用地の割合は15%である。県の中央には最上川が流れる。県民の多くがこの川の流域に住んでいるため、「母なる川」とも呼ばれている。北西側の日本海上には県唯一の離島、飛島がある。</p>
</div>
<div>
<p>日本列島の南、南西諸島の内琉球諸島を占める地域である。南西諸島のうち、屋久島、種子島、トカラ列島、奄美群島は鹿児島県に所属する。それより南で大東諸島や尖閣諸島まで含む。気候は大部分の地域で亜熱帯に属し、宮古島・多良間島・石垣島・西表島・与那国島・波照間島・沖大東島などでは最寒月平均気温が18°C以上の熱帯に属する。</p>
</div>
</div>
</div>
<br />
<br />
<!--vertical Tabs-->
<div id="verticalTab">
<ul class="resp-tabs-list">
<li>東京</li>
<li>山形</li>
<li>沖縄</li>
<li>三重</li>
</ul>
<div class="resp-tabs-container">
<div>
<p>2012年現在、国際連合の統計によると、東京は世界最大のメガシティと評価されており、川崎、横浜などとともに世界最大の人口を有する都市圏を形成している。都市単位の経済規模(GDP)ではニューヨークをしのぎ、世界最大である。2012年、アメリカのシンクタンクが公表したビジネス・人材・文化・政治などを対象とした総合的な世界都市ランキングにおいて、ニューヨーク、ロンドン、パリに次ぐ世界第4位の都市と評価された。</p>
</div>
<div>
<p>県域を地図で見ると人間の顔の形(西向きの横顔)をしている。県の東側一帯で宮城県との境に奥羽山脈、県の西部に朝日連峰がそびえているように、県域の大半 (85%) を山地が占め、総面積に対する森林の割合は 75% 、農業用地の割合は15%である。県の中央には最上川が流れる。県民の多くがこの川の流域に住んでいるため、「母なる川」とも呼ばれている。北西側の日本海上には県唯一の離島、飛島がある。</p>
</div>
<div>
<p>日本列島の南、南西諸島の内琉球諸島を占める地域である。南西諸島のうち、屋久島、種子島、トカラ列島、奄美群島は鹿児島県に所属する。それより南で大東諸島や尖閣諸島まで含む。気候は大部分の地域で亜熱帯に属し、宮古島・多良間島・石垣島・西表島・与那国島・波照間島・沖大東島などでは最寒月平均気温が18°C以上の熱帯に属する。</p>
</div>
<div>
<p>海、山の豊富な自然に恵まれ、農業・漁業が盛んである。また観光で江戸時代(御伊勢参り)から現在(F1日本グランプリや、8耐など)に至るまで、観光を産業として成り立たせており、京都府や奈良県と並び稀有な県である。</p>
</div>
</div>
</div>
<br />
<div style="height: 30px; clear: both"></div>