Tab responsive tabs custom tab activate
Demo desktop
Demo mobile
Code:
<div class='accord' id='About'><div>
<ul class='resp-tabs-list'>
<li><i class="fa fa-info-circle"></i> Giới thiệu</li>
<li><i class="fa fa-share-square-o"></i> Kênh Mạng Xã Hội</li>
<li><i class="fa fa-user-plus"></i> Hợp Tác Cùng QHMusic</li>
</ul>
<div class='resp-tabs-container'>
<div>
<p><b><a href="#" target="_blank">Domain.net</a> là một dự án mở rộng của kênh youtube <b><a href="#" target="_blank">QH MUSIC</a></b> trong năm 2016, một kênh chuyên về <b><i><a href="#" target="_blank">Nhạc DJ, Nonstop, Việt Mix</a></i></b> hàng đầu tại Việt Nam.<br />
Tại đây sẽ cập nhật những thông tin cũng như video mới nhất của kênh, hy vọng sẽ mang đến những phút giây thư giãn thoải mái nhất đến với các bạn.<br />
Ủng hộ kênh bằng cách <b><i>LIKE, SHARE & ĐĂNG KÝ</i></b> kênh nhé...<a href="#">đọc tiếp</a></b></p>
</div>
<div>
<p>
The transition had been so sudden and so unexpected that it left me for a moment forgetful of aught else than my strange metamorphosis. My first thought was, is this then death! Have I indeed passed over forever into that other life! But I could not well believe this, as I could feel my heart pounding against my ribs from the exertion of my efforts to release myself.
</p>
</div>
<div>
<p>
Hiện tại QHMUSIC.NET đang trong giai đoạn hoạt động thử nghiệm, vì vậy chúng tôi chưa triển khai các chương trình hợp tác tại trang website, rất cảm ơn bạn đã quan tâm, hy vọng một ngày nào đó không xa chúng ta sẽ cùng được làm việc với nhau.
</p>
</div>
<style>
.resp-vtabs{
min-height: 250px;
}
.resp-tabs-list li {
display: inline-block;
padding: 13px 15px;
margin: 0;
list-style: none;
cursor: pointer;
float: left;
}
.resp-tabs-container {
background-color: #FFFFFF;
clear: left;
color: #8e8e8e;
font: normal normal 14px Open Sans;
margin-top: -4px;
line-height: 27px;
padding: 0px;
}
.resp-tab-item {
color: #6e6e6e;
font: normal 600 13px Open Sans;
letter-spacing: 1px;
padding-right: 56px;
text-align: right;
text-transform: uppercase;
}
h2.resp-accordion {
cursor: pointer;
padding: 5px;
display: none;
}
.resp-tabs-container {
text-align: left;
}
.resp-tab-content {
display: none;
padding: 0px 0px 0px 28px;
}
.resp-tab-active {
border-bottom: none;
margin-bottom: -1px !important;
}
.resp-tab-item.resp-tab-active {
color: #189ca0;
}
.resp-tab-active {
border-bottom: none;
background-color: #EEEEEE;
color: #5F5F5F;
}
.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 {
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: 25%;
}
.resp-vtabs .resp-tabs-list li {
display: block;
padding: 15px 50px 15px 15px !important;
margin: 0;
cursor: pointer;
float: none;
}
.resp-vtabs .resp-tabs-container {
padding: 0px;
background-color: #fff;
float: left;
width: 70%;
border-radius: 4px;
clear: none;
}
.resp-vtabs .resp-tab-content {
border: none;
}
.resp-vtabs li.resp-tab-active {
border-right: none;
background-color: #f1f1f1;
position: relative;
z-index: 1;
margin-right: -1px !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 #8C8C8C;
position: relative;
top: 4px;
}
h2.resp-tab-active span.resp-arrow {
border: none;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 12px solid #E3E3E3;
}
/*-----------Accordion styles-----------*/
h2.resp-tab-active {
background: #474747 !important;
border-color: #434343;
color: #e8e8e8;
}
.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;
font-family: Roboto;
}
.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;
}
.resp-tabs-container .resp-accordion {
font-size: 14px;
}
h2.resp-accordion {
padding: 10px 28px;
}
h2.resp-tab-active {
padding: 10px 28px !important;
}
.resp-tab-content p {
padding: 20px 20px 20px 0;
}
}
@media only screen and (max-width: 720px) {
.services {
width: 100%;
}
.contact1.section {
width: 100%;
max-width: none;
}
.clearme {
width: 50%;
}
.title1 {
font-size: 38px;
}
}
</style>
<script type='text/javascript'>
//<![CDATA[
// Easy Responsive Tabs Plugin
// Author: Samson.Onna <Email : samson3d@gmail.com>
(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,
closed: false,
activate: function(){}
}
//Variables
var options = $.extend(defaults, options);
var opt = options, jtype = opt.type, jfit = opt.fit, jwidth = opt.width, vtabs = 'vertical', accord = 'accordion';
var hash = window.location.hash;
var historyApi = !!(window.history && history.replaceState);
//Events
$(this).bind('tabactivate', function(e, currentTab) {
if(typeof options.activate === 'function') {
options.activate.call(currentTab, e)
}
});
//Main function
this.each(function () {
var $respTabs = $(this);
var $respTabsList = $respTabs.find('ul.resp-tabs-list');
var respTabsId = $respTabs.attr('id');
$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 to accordion title
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 $tabItem = $respTabs.find('.resp-tab-item:eq(' + itemCount + ')');
var $accItem = $respTabs.find('.resp-accordion:eq(' + itemCount + ')');
$accItem.append($tabItem.html());
$accItem.data($tabItem.data());
$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');
//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++;
});
// Show correct content area
var tabNum = 0;
if(hash!='') {
var matches = hash.match(new RegExp(respTabsId+"([0-9]+)"));
if (matches!==null && matches.length===2) {
tabNum = parseInt(matches[1],10)-1;
if (tabNum > count) {
tabNum = 0;
}
}
}
//Active correct tab
$($respTabs.find('.resp-tab-item')[tabNum]).addClass('resp-tab-active');
//keep closed if option = 'closed' or option is 'accordion' and the element is in accordion mode
if(options.closed !== true && !(options.closed === 'accordion' && !$respTabsList.is(':visible')) && !(options.closed === 'tabs' && $respTabsList.is(':visible'))) {
$($respTabs.find('.resp-accordion')[tabNum]).addClass('resp-tab-active');
$($respTabs.find('.resp-tab-content')[tabNum]).addClass('resp-tab-content-active').attr('style', 'display:block');
}
//assign proper classes for when tabs mode is activated before making a selection in accordion mode
else {
$($respTabs.find('.resp-tab-content')[tabNum]).addClass('resp-tab-content-active resp-accordion-closed')
}
//Tab Click action function
$respTabs.find("[role=tab]").each(function () {
var $currentTab = $(this);
$currentTab.click(function () {
var $currentTab = $(this);
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');
}
//Trigger tab activation event
$currentTab.trigger('tabactivate', $currentTab);
//Update Browser History
if(historyApi) {
var currentHash = window.location.hash;
var newHash = respTabsId+(parseInt($tabAria.substring(9),10)+1).toString();
if (currentHash!="") {
var re = new RegExp(respTabsId+"[0-9]+");
if (currentHash.match(re)!=null) {
newHash = currentHash.replace(re,newHash);
}
else {
newHash = currentHash+"|"+newHash;
}
}
else {
newHash = '#'+newHash;
}
history.replaceState(null,null,newHash);
}
});
});
//Window resize function
$(window).resize(function () {
$respTabs.find('.resp-accordion-closed').removeAttr('style');
});
});
}
});
})(jQuery);
//]]>
</script>
<script type='text/javascript'>
//<![CDATA[
$('#About').easyResponsiveTabs({
type: 'vertical',
width: 'auto',
fit: true
});
//]]>
</script>
Ai chưa có thư viện jquery thì cho cái này thêm vào
Code:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'>
</script>
Tags: #code #forumotion #blogger