Code clean,

This commit is contained in:
2020-04-06 12:21:47 +02:00
parent 60fdf02112
commit 8fabe68241
7 changed files with 55 additions and 60 deletions

1
.env
View File

@@ -1,6 +1,7 @@
# Website # Website
PROD_URL="https://housesof.world" PROD_URL="https://housesof.world"
TRANSITION=true TRANSITION=true
HOME_PHOTOS_LIMIT=6
# API # API
API_TOKEN="NJk0urljsdSvApUDzWxGgoO6" API_TOKEN="NJk0urljsdSvApUDzWxGgoO6"

View File

@@ -7,21 +7,20 @@ import { animDelay } from 'utils/store'
** Transition In ** Transition In
*/ */
export const animateIn = (scope, init) => { export const animateIn = (scope, init) => {
const tl = anime.timeline({
easing: 'easeOutQuart',
duration: 1000
})
// Stagger each letters and words // Stagger each letters and words
tl.add({ const letters = anime({
targets: scope.querySelectorAll('span, em span'), targets: scope.querySelectorAll('span, em span'),
translateY: ['100%', 0], translateY: ['100%', 0],
easing: 'easeOutQuart',
duration: 1000,
delay: anime.stagger(40, { start: init ? 0 : animDelay }), delay: anime.stagger(40, { start: init ? 0 : animDelay }),
autoplay: false
}) })
// On scroll animation // On scroll animation
const title = ScrollOut({ const title = ScrollOut({
once: true, once: true,
targets: scope, targets: scope,
onShown: () => tl.restart() onShown: () => letters.restart()
}) })
} }

View File

@@ -36,8 +36,8 @@ export const animateIn = () => {
duration: animDuration, duration: animDuration,
autoplay: false autoplay: false
}) })
window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 10)) window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 5))
requestAnimationFrame(() => parallaxAnime(document.getElementById('title-houses'), translate), 50) requestAnimationFrame(() => parallaxAnime(document.getElementById('title-houses'), translate))
// Intro: Description // Intro: Description
const introDescription = anime({ const introDescription = anime({

View File

@@ -3,22 +3,13 @@
// Variables // Variables
let toggleEl let toggleEl
let toggleLayout let grid
let pill
let layoutSetting let layoutSetting
// Elements
/*
** Run code when mounted
*/
onMount(() => {
// Get layout setting from storage
layoutSetting = (localStorage.getItem('photosLayout')) ? localStorage.getItem('photosLayout') : 'list'
// Variables
const layoutGridClass = 'photos--grid' const layoutGridClass = 'photos--grid'
const layoutListClass = 'photos--list' const layoutListClass = 'photos--list'
const grid = document.querySelector('.photos')
const pill = toggleEl.querySelector('.pill')
// Change active pill // Change active pill
const toggleAnimate = (elem, pill, toggle) => { const toggleAnimate = (elem, pill, toggle) => {
@@ -26,11 +17,8 @@
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px' pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
} }
// Init of first option
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
// Toggle layout // Toggle layout
toggleLayout = event => { const toggleLayout = event => {
const clicked = event.currentTarget const clicked = event.currentTarget
const type = clicked.dataset.layout const type = clicked.dataset.layout
@@ -57,6 +45,19 @@
// Remember this setting // Remember this setting
localStorage.setItem('photosLayout', type) localStorage.setItem('photosLayout', type)
} }
/*
** Run code when mounted
*/
onMount(() => {
grid = document.querySelector('.photos')
// Get layout setting from storage
layoutSetting = (localStorage.getItem('photosLayout')) ? localStorage.getItem('photosLayout') : 'list'
// Init of first option
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
}) })
</script> </script>
@@ -84,5 +85,5 @@
<span>Grid</span> <span>Grid</span>
</button> </button>
<div class="pill" aria-hidden="true" role="presentation"></div> <div class="pill" aria-hidden="true" role="presentation" bind:this={pill}></div>
</div> </div>

View File

@@ -9,7 +9,6 @@
description description
explore_globe explore_globe
explore_list explore_list
homepage_photos_limit
photos_per_page photos_per_page
instagram instagram
seo_name seo_name

View File

@@ -1,6 +1,6 @@
<script context="module"> <script context="module">
// Variables // Variables
let limit let limit = process.env.CONFIG.HOME_PHOTOS_LIMIT
// Preload data (photos to display) // Preload data (photos to display)
export async function preload (page, session) { export async function preload (page, session) {
@@ -11,9 +11,6 @@
] ]
// Random sort // Random sort
const sort = '?' const sort = '?'
// Get the limit from API
site.subscribe(store => limit = store.homepage_photos_limit)
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`) const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`)
const photos = await req.json() const photos = await req.json()
if (req.ok) { if (req.ok) {
@@ -103,10 +100,8 @@
</div> </div>
<div id="intro-carousel"> <div id="intro-carousel">
{#if photos}
<Carousel {photos} /> <Carousel {photos} />
<Fullscreen /> <Fullscreen />
{/if}
</div> </div>
</section> </section>

View File

@@ -37,7 +37,7 @@
{#if show || !process.browser} {#if show || !process.browser}
<slot /> <slot />
{:else} {:else if process.env.CONFIG.TRANSITION}
<div class="transition" id="transition" aria-hidden="true" bind:this={scope}> <div class="transition" id="transition" aria-hidden="true" bind:this={scope}>
<div class="transition__loader" <div class="transition__loader"
in:fly={{ y: 32, duration: 1000, easing: quartOut }} in:fly={{ y: 32, duration: 1000, easing: quartOut }}