Hide all elements but the first 12
Hi,
The else if part of this code is not working. Does any one know why?
HTML
- <div class="row tile-list-wrapper tile-person-list">
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
- <div class="js-reveal-target">
- <!--#include file="tile-person.html" -->
- </div>
-
- <div class="columns">
- <button class="button hollow primary js-reveal-more-trigger">See more people</button>
- </div>
- </div>
JQuery
- var allInstances = $('.js-reveal-target'),
- revealMoreButtons = $('.js-reveal-more-trigger'),
- numberToShow = 2;
- var revealEffect = function () {
- allInstances.slice(0, numberToShow).show();
- if ($('.js-reveal-target:hidden').length > 0) {
- revealMoreButtons.on('click', function (e) {
- e.preventDefault();
- $('.js-reveal-target:hidden').slice(0, numberToShow).slideDown();
- $('html,body').animate({
- scrollTop: $(this).offset().top
- }, 1500);
- });
- } else if ($('.js-reveal-target:hidden').length == 0) {
- revealMoreButtons.text('See less people');
- revealMoreButtons.on('click', function (e) {
- e.preventDefault();
- $('.js-reveal-target').slice(0, numberToShow).hide();
- });
- }
- }; // End of revealEffect function