Created
June 14, 2018 00:48
-
-
Save muks999/a62a72f7bc382c89b81ae5e03002f2b5 to your computer and use it in GitHub Desktop.
Tabs Native JS
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
(function () { | |
let tabNav = document.querySelectorAll('.tab-list>li'), | |
tabContent = document.querySelectorAll('.tab-content__item'), | |
tabName; | |
tabNav.forEach(function (item) { | |
item.addEventListener('click', selectTabNav) | |
}); | |
function selectTabNav() { | |
tabNav.forEach(function (item) { | |
item.classList.remove( ); // Удаляем активный укласс у элемента списка | |
}); | |
this.classList.add( ); // Добавляем активный укласс у элемента списка | |
tabName = this.getAttribute('data-tab'); | |
selectTabContent(tabName); | |
} | |
function selectTabContent(tab) { | |
tabContent.forEach(function (item) { | |
if (item.classList.contains(tab)) { | |
item.classList.add('tab-content__item--active'); | |
} else { | |
item.classList.remove('tab-content__item--active'); | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment