Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from Shamsudeen12/image-edit
Browse files Browse the repository at this point in the history
Added A specified height for each thumbnail and lazy loading for imag…
  • Loading branch information
lucasweng committed Oct 13, 2018
2 parents c935e8f + 678b774 commit 00f9f36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions public/js/script.js
@@ -0,0 +1,6 @@
[].forEach.call(document.querySelectorAll('img[data-src]'), function(img) {
img.setAttribute('src', img.getAttribute('data-src'));
img.onload = function() {
img.removeAttribute('data-src');
};
});
10 changes: 9 additions & 1 deletion public/styles/main.css
Expand Up @@ -36,12 +36,21 @@ a:visited {
/* image stying */
.thumbnail img {
width: 100%;
opacity: 1;
transition: opacity 0.3s;
}

.thumbnail img[data-src] {
opacity: 0;
}

.thumbnail {
padding: 0;
}

.campground__image {
height: 150px;
}
/* tent logo */
span .align-bottom {
vertical-align: bottom;
Expand Down Expand Up @@ -82,4 +91,3 @@ span .align-bottom {
height: 400px;
width: 100%;
}

4 changes: 2 additions & 2 deletions views/campgrounds/index.ejs
Expand Up @@ -17,15 +17,15 @@
</header>

<div class="row text-center" style="display: flex; flex-wrap: wrap;">
<% if (noMatch !== null) {%>
<% if (noMatch !== null) {%>
<div class="col-md-12">
<h4><%= noMatch %></h4>
</div>
<% } %>
<% campgrounds.forEach(campground => {%>
<div class="col-md-3 col-sm-6">
<div class="thumbnail card">
<img src="<%= campground.image.url %>" alt="<%= campground.name %>" />
<img class="campground__image" data-src="<%= campground.image.url %>" alt="<%= campground.name %>" />
<div class="caption">
<h4 class="caption"><%= campground.name %></h4>
</div>
Expand Down
3 changes: 2 additions & 1 deletion views/partials/footer.ejs
Expand Up @@ -9,5 +9,6 @@
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src="/js/script.js"></script>
</body>
</html>
</html>

0 comments on commit 00f9f36

Please sign in to comment.