-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add background grid and random pixels
- Loading branch information
1 parent
712131e
commit df37e12
Showing
5 changed files
with
102 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
<script> | ||
import { fade } from 'svelte/transition'; | ||
function getRandomInt(max) { | ||
return Math.floor(Math.random() * max); | ||
} | ||
let innerWidth = 0; | ||
let innerHeight = 0; | ||
let x = 0; | ||
let y = 0; | ||
let show = false; | ||
let duration = getRandomInt(5000); | ||
function update() { | ||
x = getRandomInt(innerWidth / 20) * 20; | ||
y = getRandomInt(innerHeight / 20) * 20; | ||
show = true; | ||
} | ||
function fadeOut() { | ||
duration = 2000 + getRandomInt(5000); | ||
setTimeout(() => { | ||
show = false; | ||
}, duration); | ||
} | ||
setTimeout(update, getRandomInt(10000)); | ||
</script> | ||
|
||
<svelte:window bind:innerWidth bind:innerHeight /> | ||
|
||
{#if show} | ||
<div transition:fade={{ duration: 5000 }} | ||
on:introend={fadeOut} | ||
on:outroend={update} | ||
style:left="{x}px" style:top="{y}px" class="pixel"></div> | ||
{/if} | ||
|
||
<style> | ||
.pixel { | ||
height: 20px; | ||
width: 20px; | ||
background-color: rgb(227, 227, 227); | ||
position: absolute; | ||
z-index: 0; | ||
} | ||
</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