Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

Commit

Permalink
add scroll event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamy committed May 24, 2020
1 parent 4a7c234 commit eb5c981
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import getEmojis from './helpers/getEmojis';
export let maxLength = 20;
let scrollY, innerHeight, body;
const emojisFull = [...getEmojis()];
let emojis = emojisFull;
Expand All @@ -21,8 +22,17 @@
const addEmojis = e => {
emojisView = emojis.slice(0, emojisView.length + maxLength);
}
const handleScroll = e => {
const scrollEnd = scrollY + innerHeight;
const { scrollHeight } = document.body;
const windowEnd = Math.abs(scrollHeight - scrollEnd) < 50;
if(windowEnd) addEmojis();
}
</script>

<svelte:window bind:innerHeight bind:scrollY on:scroll={handleScroll}/>

<main>
<Input on:input={handleInput} />
{#if emojisView.length}
Expand Down

0 comments on commit eb5c981

Please sign in to comment.