JQuery Load more

Simple Load More Trick…

 

Add this in html:


<div class="container">
 <div class="flex">
  <div class="content">Box 1</div>
  <div class="content">Box 2</div>
  <div class="content">Box 3</div>
  <div class="content">Box 4</div>
  <div class="content">Box 5</div>
  <div class="content">Box 6</div>
  <div class="content">Box 7</div>
  <div class="content">Box 8</div>
  <div class="content">Box 9</div>
  <div class="content">Box 10</div>
  <div class="content">Box 11</div>
 </div>

 <a href="#" id="loadMore">Load More</a>
</div>

Add this in css:


.flex {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
} 
.content {
height: 100px;
width: 45%;
color: #fff;
font-size: 24px;
line-height: 100px; /* centering text just for view */
text-align: center;
background-color: grey;
margin: 5px;
border: 1px solid lightgrey;
display: none;
}
#loadMore {
width: 200px;
color: #fff;
display: block;
text-align: center;
margin: 20px auto;
padding: 10px;
border-radius: 10px;
border: 1px solid transparent;
background-color: blue;
transition: .3s;
}
#loadMore:hover {
color: blue;
background-color: #fff;
border: 1px solid blue;
text-decoration: none;
}
.noContent {
color: #000 !important;
background-color: transparent !important;
pointer-events: none;
}

Add this in <script> tags:


$(document).ready(function(){
$(".content").slice(0, 4).show();
$("#loadMore").on("click", function(e){
e.preventDefault();
$(".content:hidden").slice(0, 4).slideDown();
if($(".content:hidden").length == 0) {
$("#loadMore").text("No Content").addClass("noContent");
}
});

})