Lazy Load Images within a Bootstrap Grid

by Ali Khaled

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://rawgit.com/toddmotto/echo/master/dist/echo.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<div id="theGrid">
	<div class="container">
		<div class="row" id="recipegrid">

			<div class="col-6 box" onclick="location.href='https://www.solodev.com/blog/web-design/add-text-transitions-to-your-hero-sliders.stml'">
				<div class="imgHolder">
					<img src="https://www.solodev.com/_/images/client-loader.gif" data-echo="https://raw.githubusercontent.com/solodev/bootstrap-lazy-load/master/image-1.jpg" class="img-responsive cover">
					<div class="in-box w-100">
						<div class="super-box h-100 w-100 text-center d-flex justify-content-center align-items-center">
							<div class="box-text">
								<p class="font-weight-bold">View Tutorial</p>
							</div>
						</div>
					</div>
				</div>
			
				
        
        
        
				<div class="description-box">
					<p class="article_name font-weight-bold text-center">How to Make the Ultimate Mobile Menu</p>
				</div>
			</div>				
		
        </div>
    </div>
</div>

CSS

.cover {
  object-fit: cover;
  height: 100%;
  width: 100%;
}
.imgHolder {
      height: 260px;
    overflow: hidden;
    position: relative;
}
#theGrid .box {
  cursor: pointer;
  margin-bottom: 10px;
  padding: 0 5px;
  min-height: 390px;
}
p.article_name {
  font-size: 1.2rem;
  line-height: 24px;
  color: #0479c3;
  padding: 5px;
}
#theGrid .imgHolder:hover  .description-box {
  background-color: rgba(217,38,44,0.8);
  cursor: pointer;
}
#theGrid .in-box {
  width: 100%;
  height: 260px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}
#theGrid .box-text p {
  opacity: 0;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
  color: #fff;
  font-size: 32px;
  margin-bottom: 0;
}
#theGrid .imgHolder:hover .box-text p {
  opacity: 1;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter: alpha(opacity=100);
}
#theGrid .imgHolder:hover .in-box {
  background-color: rgba(41, 141, 204, 0.701961);
  cursor: pointer;
}
@media (max-width: 600px){
    #theGrid .box {
      width: 100%;
  }
}

JavaScript

echo.init();