Terminada funcionalidad de fondos
This commit is contained in:
17
index.html
17
index.html
@@ -11,6 +11,23 @@
|
|||||||
|
|
||||||
<div id="photos-box" class="box">
|
<div id="photos-box" class="box">
|
||||||
<div class="photos" id="photos-div"></div>
|
<div class="photos" id="photos-div"></div>
|
||||||
|
<div class="photos-controls">
|
||||||
|
<button id="photos-prev">Anterior</button>
|
||||||
|
<span id="photos-page">1</span>
|
||||||
|
<button id="photos-next">Siguiente</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="search-box" class="box">
|
||||||
|
<input class="search-box" name="search" placeholder="Busqueda"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="weather-box" class="box">
|
||||||
|
<p>Weather</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="custom-box" class="box">
|
||||||
|
<p>Custom</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="currency-box" class="box">
|
<div id="currency-box" class="box">
|
||||||
|
|||||||
72
script.js
72
script.js
@@ -83,7 +83,10 @@ const currency = new function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const photos = new function() {
|
const photos = new function() {
|
||||||
|
this.msnry = null;
|
||||||
|
this.imgs = [];
|
||||||
this.current_photos = null;
|
this.current_photos = null;
|
||||||
|
this.current_page = 1;
|
||||||
|
|
||||||
this.query_photos = async (page) => {
|
this.query_photos = async (page) => {
|
||||||
// Llama a la api para obtener una lista de imagenes
|
// Llama a la api para obtener una lista de imagenes
|
||||||
@@ -110,21 +113,15 @@ const photos = new function() {
|
|||||||
|
|
||||||
this.set_as_background = async (url) => {
|
this.set_as_background = async (url) => {
|
||||||
document.querySelector('.container').style.backgroundImage= `url(${url})`
|
document.querySelector('.container').style.backgroundImage= `url(${url})`
|
||||||
|
localStorage.setItem('background', url)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fill_photos = async (page) => {
|
this.clear_photos = async () => {
|
||||||
const photos = await this.query_photos(page)
|
this.imgs.forEach(img => {
|
||||||
const photos_div = document.getElementById('photos-div')
|
this.msnry.remove(img)
|
||||||
|
|
||||||
photos.results.forEach((photo) => {
|
|
||||||
const img = document.createElement('img')
|
|
||||||
img.src = photo.urls.small
|
|
||||||
img.alt = photo.alt
|
|
||||||
|
|
||||||
photos_div.appendChild(img)
|
|
||||||
img.addEventListener('click', () => this.set_as_background(photo.urls.full))
|
|
||||||
})
|
})
|
||||||
|
this.msnry.layout()
|
||||||
|
this.imgs = []
|
||||||
}
|
}
|
||||||
|
|
||||||
this.wait_for_load = () => {
|
this.wait_for_load = () => {
|
||||||
@@ -135,21 +132,62 @@ const photos = new function() {
|
|||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.fill_photos = async () => {
|
||||||
|
const photos = await this.query_photos(this.current_page)
|
||||||
|
const photos_div = document.getElementById('photos-div')
|
||||||
|
const photos_page = document.getElementById('photos-page')
|
||||||
|
const fragment = document.createDocumentFragment()
|
||||||
|
|
||||||
this.on_load = async () => {
|
photos.results.forEach((photo) => {
|
||||||
await this.fill_photos(1)
|
const img = document.createElement('img')
|
||||||
|
img.src = photo.urls.small
|
||||||
|
img.alt = photo.alt
|
||||||
|
img.addEventListener('click', () => this.set_as_background(photo.urls.full))
|
||||||
|
|
||||||
|
fragment.appendChild(img)
|
||||||
|
this.imgs.push(img)
|
||||||
|
})
|
||||||
|
|
||||||
|
photos_page.innerHTML = this.current_page;
|
||||||
|
|
||||||
|
photos_div.appendChild(fragment)
|
||||||
await this.wait_for_load()
|
await this.wait_for_load()
|
||||||
|
|
||||||
var msnry = new Masonry( '.photos', {
|
this.msnry.appended(this.imgs)
|
||||||
|
this.msnry.layout()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.next_page = async () => {
|
||||||
|
this.current_page++
|
||||||
|
await this.clear_photos()
|
||||||
|
await this.fill_photos()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.previous_page = async () => {
|
||||||
|
if(this.current_page - 1 >= 1) {
|
||||||
|
this.current_page--
|
||||||
|
await this.clear_photos()
|
||||||
|
await this.fill_photos()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on_load = async () => {
|
||||||
|
const previous_background = localStorage.getItem('background')
|
||||||
|
if(previous_background !== null) this.set_as_background(previous_background)
|
||||||
|
|
||||||
|
this.msnry = new Masonry( '.photos', {
|
||||||
itemSelector: 'img',
|
itemSelector: 'img',
|
||||||
percentPosition: true,
|
percentPosition: true,
|
||||||
gutter: 10,
|
gutter: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.fill_photos()
|
||||||
|
|
||||||
|
document.getElementById('photos-next').addEventListener('click', this.next_page);
|
||||||
|
document.getElementById('photos-prev').addEventListener('click', this.previous_page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
currency.on_load()
|
currency.on_load()
|
||||||
photos.on_load()
|
photos.on_load()
|
||||||
|
|||||||
62
styles.css
62
styles.css
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* BASE
|
||||||
|
*/
|
||||||
|
|
||||||
* {
|
* {
|
||||||
font-family: sans;
|
font-family: sans;
|
||||||
}
|
}
|
||||||
@@ -6,24 +10,44 @@
|
|||||||
background-image: linear-gradient(to top, #4481eb 0%, #04befe 100%);
|
background-image: linear-gradient(to top, #4481eb 0%, #04befe 100%);
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
|
||||||
display: grid;
|
display: grid;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow: scroll;
|
||||||
|
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(10, minmax(130px, 1fr));
|
||||||
grid-template-rows: repeat(4, 1fr);
|
grid-template-rows: repeat(13, 1fr);
|
||||||
gap: 10px;
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#photos-box {
|
#photos-box {
|
||||||
|
grid-row: 1 / 14;
|
||||||
|
grid-column: 1 / 3;
|
||||||
|
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
#search-box {
|
||||||
|
grid-row: 2 / 4;
|
||||||
|
grid-column: 4 / 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
#weather-box {
|
||||||
grid-row: 1 / 4;
|
grid-row: 1 / 4;
|
||||||
grid-col: 1;
|
grid-column: 9 / 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
#custom-box {
|
||||||
|
grid-row: 4 / 10;
|
||||||
|
grid-column: 9 / 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
#currency-box {
|
#currency-box {
|
||||||
grid-row: 4;
|
grid-row: 10 / 14;
|
||||||
grid-col: 1;
|
grid-column: 9 / 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
.box {
|
.box {
|
||||||
@@ -35,9 +59,13 @@
|
|||||||
padding: 1em;
|
padding: 1em;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
|
||||||
box-shadow: rgba(0, 0, 0, 0.4) 0px 30px 90px;
|
box-shadow: rgba(255, 255, 255, 0.1) 0px 1px 1px 0px inset, rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Currency
|
||||||
|
*/
|
||||||
|
|
||||||
.box .currency {
|
.box .currency {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -86,9 +114,14 @@
|
|||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Photos
|
||||||
|
*/
|
||||||
|
|
||||||
.box .photos {
|
.box .photos {
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.photos img {
|
.photos img {
|
||||||
@@ -96,3 +129,16 @@
|
|||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#photos-page {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box .photos-controls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user