-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cfac74
commit 5934871
Showing
10 changed files
with
192 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<script lang="typescript"> | ||
export let src: string; | ||
export let alt: string; | ||
import { onMount } from 'svelte'; | ||
let loaded = false; | ||
let thisImage: HTMLElement; | ||
onMount(() => { | ||
thisImage.onload = () => { | ||
loaded = true; | ||
}; | ||
}); | ||
</script> | ||
|
||
<div class="img-container"> | ||
<img {src} {alt} class:loaded bind:this={thisImage} loading="lazy" /> | ||
</div> | ||
|
||
<style> | ||
.img-container { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 140px; | ||
} | ||
img { | ||
max-width: 100%; | ||
max-height: 100%; | ||
height: auto; | ||
opacity: 0; | ||
transition: opacity 1300ms ease-out; | ||
} | ||
img.loaded { | ||
opacity: 1; | ||
} | ||
@media (min-width: 360px) { | ||
.img-container { | ||
height: 190px; | ||
} | ||
} | ||
@media (min-width: 700px) { | ||
.img-container { | ||
height: 350px; | ||
} | ||
} | ||
@media (min-width: 960px) { | ||
.img-container { | ||
height: 250px; | ||
} | ||
} | ||
@media (min-width: 1280px) { | ||
.img-container { | ||
height: 180px; | ||
} | ||
} | ||
@media (min-width: 1600px) { | ||
.img-container { | ||
height: 180px; | ||
} | ||
} | ||
@media (min-width: 2000px) { | ||
.img-container { | ||
height: 225px; | ||
} | ||
} | ||
</style> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="typescript"> | ||
import IntersectionObserver from './IntersectionObserver.svelte'; | ||
import Image from './Image.svelte'; | ||
export let src: string; | ||
export let alt: string; | ||
</script> | ||
|
||
<IntersectionObserver once={true} let:intersecting> | ||
{#if intersecting} | ||
<Image {alt} {src} /> | ||
{/if} | ||
</IntersectionObserver> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script lang="typescript"> | ||
import { onMount } from 'svelte'; | ||
export let once = false; | ||
export let top = 0; | ||
export let bottom = 0; | ||
export let left = 0; | ||
export let right = 0; | ||
let intersecting = false; | ||
let container: HTMLElement; | ||
onMount(() => { | ||
if (typeof IntersectionObserver !== 'undefined') { | ||
const rootMargin = `${bottom}px ${left}px ${top}px ${right}px`; | ||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
intersecting = entries[0].isIntersecting; | ||
if (intersecting && once) { | ||
observer.unobserve(container); | ||
} | ||
}, | ||
{ | ||
rootMargin, | ||
} | ||
); | ||
observer.observe(container); | ||
return () => observer.unobserve(container); | ||
} | ||
// The following is a fallback for older browsers | ||
function handler() { | ||
const bcr = container.getBoundingClientRect(); | ||
intersecting = | ||
bcr.bottom + bottom > 0 && | ||
bcr.right + right > 0 && | ||
bcr.top - top < window.innerHeight && | ||
bcr.left - left < window.innerWidth; | ||
if (intersecting && once) { | ||
window.removeEventListener('scroll', handler); | ||
} | ||
} | ||
window.addEventListener('scroll', handler); | ||
return () => window.removeEventListener('scroll', handler); | ||
}); | ||
</script> | ||
|
||
<div bind:this={container}> | ||
<slot {intersecting} /> | ||
</div> | ||
|
||
<style> | ||
div { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> |
This file contains 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
This file contains 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
This file contains 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