From 2580c5dcb9f1e5e6541f63f8c7e24e5dfc82f078 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 24 Dec 2021 09:45:51 +0100 Subject: Add snow effect for Christmas time --- assets/css/objects/_icon.scss | 15 +++++++++++++++ content/script.js | 22 ++++++++++++++++++++++ content/symbols.svg | 4 ++++ templates/base.html | 2 ++ 4 files changed, 43 insertions(+) create mode 100644 content/script.js diff --git a/assets/css/objects/_icon.scss b/assets/css/objects/_icon.scss index cbce5cf..6718c50 100644 --- a/assets/css/objects/_icon.scss +++ b/assets/css/objects/_icon.scss @@ -1,4 +1,10 @@ @include namespace('icon') { + @keyframes fall { + to { + transform: translateY(105vh) rotate(90deg); + } + } + @include object(namespace()) { display: block; width: 16px; @@ -11,5 +17,14 @@ display: inline-block; vertical-align: -.1em; } + + @include modifier('snow') { + position: fixed; + z-index: 9999; + top: -20px; + animation: fall linear forwards; + stroke-width: 2px; + color: #fff; + } } } diff --git a/content/script.js b/content/script.js new file mode 100644 index 0000000..5702edf --- /dev/null +++ b/content/script.js @@ -0,0 +1,22 @@ +function createSnowFlake() { + const snowFlake = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + const snowFlakeInner = document.createElementNS("http://www.w3.org/2000/svg", "use"); + + snowFlakeInner.setAttribute("href", "/symbols.svg#icon-asterisk"); + + snowFlake.classList.add("o-icon"); + snowFlake.classList.add("o-icon--snow"); + snowFlake.ariaHidden = true; + + snowFlake.style.width = Math.random() * 10 + 10 + 'px'; + snowFlake.style.left = Math.random() * window.innerWidth + 'px'; + snowFlake.style.animationDuration = Math.random() * 3 + 2 + 's'; + snowFlake.style.opacity = Math.random(); + + snowFlake.appendChild(snowFlakeInner); + document.body.appendChild(snowFlake); + + setTimeout(() => { snowFlake.remove(); }, 5000); +} + +window.addEventListener("load", () => { setInterval(createSnowFlake, 100); }) diff --git a/content/symbols.svg b/content/symbols.svg index df6ddd9..97992fc 100644 --- a/content/symbols.svg +++ b/content/symbols.svg @@ -8,6 +8,10 @@ + + + + diff --git a/templates/base.html b/templates/base.html index 353a2bd..c1e1f4f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -82,6 +82,8 @@ ${layouts/page()} + + -- cgit v1.2.3-54-g00ecf