Created
June 27, 2019 12:03
-
-
Save kisildev/ea1cd1579f105c2d80777364e1047066 to your computer and use it in GitHub Desktop.
Filtration and load more btn
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
// Technologies filtration | |
var $container = $('.js-technologies-grid'); | |
var $termsBox = $('.js-technologies-terms'); | |
var $termsNav = $('.js-technologies-term'); | |
var $allTermItems = $('.js-technologies-item'); | |
var $loadMoreBtn = $('.js-load-more'); | |
$termsBox.on('click', function(e) { | |
var $target = $(e.target); | |
if ($target.hasClass('js-technologies-term')) { | |
// Get term name | |
var curretItem = $target.data('nav-term'); | |
// Get current elems to load | |
var $itemsToLoad = $('[data-term="'+$target.data('nav-term')+'"]'); | |
// Highlighting nav | |
$termsNav.removeClass('active'); | |
$target.addClass('active'); | |
// Displaing elems func | |
function displayItems($items) { | |
var allItemCount = $items.length; | |
$allTermItems.hide(); | |
$items.each(function(index, el) { | |
if (index > 6) { return false; } | |
$(el).show(); | |
}); | |
if(allItemCount > 6) { | |
$loadMoreBtn.show(); | |
} else { | |
$loadMoreBtn.hide(); | |
} | |
} | |
// Displaing elems | |
if (curretItem == 'all') { | |
displayItems($allTermItems); | |
} else { | |
displayItems($itemsToLoad); | |
} | |
} | |
}); | |
// Load more | |
if ($('.js-load-more').length) { | |
$loadMoreBtn.on('click', function(e) { | |
event.preventDefault(); | |
// Get active item from nav | |
var activeTerm = $(this) | |
.closest($container) | |
.find('.js-technologies-term.active') | |
.data('nav-term'); | |
// Loading current elems | |
if (activeTerm == 'all') { | |
$allTermItems.show(); | |
$(this).hide(); | |
} else { | |
$('[data-term="'+activeTerm+'"]').show(); | |
$(this).hide(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment