Skip to content

Instantly share code, notes, and snippets.

@Rachind
Last active December 9, 2016 06:20
Show Gist options
  • Save Rachind/fc65185ae243c7bd64a837722136e418 to your computer and use it in GitHub Desktop.
Save Rachind/fc65185ae243c7bd64a837722136e418 to your computer and use it in GitHub Desktop.
Jquery show more
jQuery.fn.extend({
hideOther: function(num){
var elem = $(this);
$(elem).wrapAll('<div class="other-all-outer"></div>').attr('data-num', 2).after('<div class="more-btn btn btn-transparent">Загрузить еще</div>').children('.item').slice(num).wrapAll('<div class="other-all"></div>').parent().hide();
$(this).closest('.other-all-outer').find('.more-btn').on('click', function(e){
e.preventDefault();
var offset_num = parseInt($(elem).data('num')),
count = num * offset_num;
$(this).closest('.other-all-outer').find('.other-all').children('.item').unwrap();
offset_num++;
$(elem).data('num', offset_num).children('.item').slice(count).wrapAll('<div class="other-all"></div>');
if($('.other-all', elem).length == 0) $(this).hide();
})
}
})
$('section.gallery .swiper-wrapper').hideOther(8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment