Created
October 8, 2022 16:31
-
-
Save TheLustriVA/183b02e58fe08773226bd6a5b0ec1656 to your computer and use it in GitHub Desktop.
Unsplash vueJS infinite scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="hero is-fullheight is-bold is-info"> | |
<div class="hero-body"> | |
<div class="container"> | |
<div class="header content"> | |
<h2 class="subtitle is-6">Code Challenge #16</h2> | |
<h1 class="title is-1"> | |
Infinite Scroll Unsplash Code Challenge | |
</h1> | |
</div> | |
<div v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="20"> | |
<div class="image-grid"> | |
<div class="image-item" v-for="photo in photos" :style="{ 'background-color': photo.color }"> | |
<a :href="photo.links.download" target="_blank" /> | |
<img :src="photo.urls.regular"> | |
<div class="overlay"> | |
<div class="download">+</div> | |
</div> | |
</a> | |
</div> | |
</div> | |
</div> | |
<img v-if="loading === true" id="loader-img" src="https://res.cloudinary.com/chuloo/image/upload/v1550093026/scotch-logo-gif_jq4tgr.gif" /> | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const apiRoot = "https://api.unsplash.com"; | |
const accessKey = | |
"afa83606113a74d2e1a55e289f05fa0ca4caedf39bfc390ec4dfc39e4275891a"; | |
const count = 5; | |
new Vue({ | |
el: ".container", | |
data: { | |
photos: [], | |
loading: false | |
}, | |
methods: { | |
loadMore() { | |
if(! this.loading){ | |
this.loading = true; | |
fetch(`${apiRoot}/photos/random?client_id=${accessKey}&count=${count}`) | |
.then((res) => { | |
return res.json(); | |
}) | |
.then(data => { | |
// console.log(json); | |
this.photos.push(...data); | |
this.loading = false; | |
}) | |
.catch(err => { | |
console.log(err); | |
this.loading = false; | |
}); | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
<script src="https://unpkg.com/[email protected]/vue-infinite-scroll.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.title { | |
font-family: "Carter One"; | |
} | |
.container { | |
margin-top: 50px; | |
text-align: center; | |
} | |
.image-grid { | |
display: grid; | |
grid-gap: 8px; | |
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | |
grid-auto-rows: minmax(25px, auto); | |
} | |
.image-grid .image-item:nth-child(5n) { | |
grid-column-end: span 2; | |
} | |
.image-grid img { | |
display: flex; | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
/*border-radius: 5px;*/ | |
} | |
.overlay { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
height: 100%; | |
width: 100%; | |
opacity: 0; | |
transition: 0.5s ease; | |
background-color: rgba(0, 0, 0, 0.6); | |
} | |
.image-item { | |
position: relative; | |
} | |
.image-item:hover .overlay { | |
box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.5); | |
opacity: 1; | |
} | |
.download { | |
color: white; | |
font-size: 50px; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
-webkit-transform: translate(-50%, -50%); | |
-ms-transform: translate(-50%, -50%); | |
transform: translate(-50%, -50%); | |
text-align: center; | |
} | |
#loader-img { | |
position: fixed; | |
bottom: 3vh; | |
left: calc(50vw - 75px); | |
width: 150px; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" /> | |
<link href="https://fonts.googleapis.com/css?family=Carter+One" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment