static load more items - Free Download Static Load More Content Plugin With jQuery - Show More Items

Free Download Static Load More Content Plugin With jQuery – Show More Items

Posted on

This time I will share jQuery Plugin and tutorial about Static Load More Content Plugin With jQuery – Show More Items, hope it will help you in programming stack.

static load more items - Free Download Static Load More Content Plugin With jQuery - Show More Items
File Size: 2.8 KB
Views Total: 115
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A simple jQuery script that can be used to hide part of your content (such as a long list) and reveal it when the user clicks the Load More button.

How to use it:

1. Supposed that you have a long content list as follows:

01 <div class="items">
02   <div class="item">Item 1</div>
03   <div class="item">Item 2</div>
04   <div class="item">Item 3</div>
05   <div class="item">Item 4</div>
06   <div class="item">Item 5</div>
07   <div class="item">Item 6</div>
08   <div class="item">Item 7</div>
09   <div class="item">Item 8</div>
10   <div class="item">Item 9</div>
11   <div class="item">Item 10</div>
12   <div class="item">Item 11</div>
13   <div class="item">Item 12</div>
14 </div>

2. Create a Load More button to display next N items.

1 <div class="buttonToogle" style="display: none;">
2   <a href="javascript:;" class="showMore">+ View More</a>
3 </div>

3. Load the latest jQuery JavaScript library at the end of the document.

1 <script src="/path/to/cdn/jquery.min.js"></script>

4. The main JavaScript (jQueryScript) to enable the Load More button.

01 $(function() {
02  
03   // items to show
04   var increment = 3;
05  
06   var startFilter = 0;
07   var endFilter = increment;
08  
09   // item selector
10   var $this = $('.items');
11  
12   var elementLength = $this.find('div').length;
13   $('.listLength').text(elementLength);
14  
15   // show/hide the Load More button
16   if (elementLength > 2) {
17     $('.buttonToogle').show();
18   }
19  
20   $('.items .item').slice(startFilter, endFilter).addClass('shown');
21   $('.shownLength').text(endFilter);
22   $('.items .item').not('.shown').hide();
23   $('.buttonToogle .showMore').on('click', function() {
24     if (elementLength > endFilter) {
25       startFilter += increment;
26       endFilter += increment;
27       $('.items .item').slice(startFilter, endFilter).not('.shown').addClass('shown').toggle(500);
28       $('.shownLength').text((endFilter > elementLength) ? elementLength : endFilter);
29       if (elementLength <= endFilter) {
30           $(this).remove();
31       }
32     }
33   });
34  
35 });