Created
September 26, 2018 03:57
-
-
Save ivan-kalachikov/18b8cbc9bd91883d91bedfee763bc8d6 to your computer and use it in GitHub Desktop.
light tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//tab-content | |
$(".tabs").lightTabs(); | |
(function($){ | |
jQuery.fn.lightTabs = function(options){ | |
var hash = window.location.hash.slice(1); | |
var createTabs = function(){ | |
var tabs = this; | |
var i = 0; | |
var page = 0; | |
var showPage = function(i){ | |
$(tabs).children("div").children("div").hide(); | |
$(tabs).children("div").children("div").eq(i).show(); | |
$(tabs).find('.tabs-nav li').removeClass("active"); | |
$(tabs).find('.tabs-nav li').eq(i).addClass("active"); | |
} | |
if (hash !== '') { | |
if ($(tabs).find('.tab[data-tab="' +hash + '"]').length > 0) { | |
window.onload = function () { | |
window.scrollTo(0, 0); | |
}; | |
page = $(tabs).find('.tabs-wrap .tab').index($(tabs).find('.tab[data-tab="' + hash + '"]')); | |
}; | |
}; | |
showPage(page); | |
$(tabs).find('.tabs-nav li').each(function(index, element){ | |
$(element).attr("data-page", i); | |
i++; | |
}); | |
$(tabs).find('.tabs-nav li').click(function(){ | |
showPage(parseInt($(this).attr("data-page"))); | |
}); | |
}; | |
return this.each(createTabs); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment