-
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.
Merge pull request #76 from JHWelch/use-made-with-package
Use made-with from package
- Loading branch information
Showing
6 changed files
with
15 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,102 +1 @@ | ||
<div | ||
x-data="{ | ||
emojis: [ | ||
'❤', | ||
'🍜', | ||
'🍕', | ||
'🍔', | ||
'🦇', | ||
'🎃', | ||
'👻', | ||
'🍬', | ||
'🐱', | ||
'🐶', | ||
'👽', | ||
'🚀', | ||
'👾', | ||
], | ||
firstEmoji: '❤', | ||
init: function (firstInit = true, groups = 1, duration = 1) { | ||
const spinner = document.querySelector('#spinner'); | ||
const emojis = spinner.querySelector('#emojis'); | ||
const emojisClone = emojis.cloneNode(false); | ||
if (firstInit) { | ||
this.firstEmoji = this.randomEmoji(); | ||
} | ||
const pool = [this.firstEmoji]; | ||
if (!firstInit) { | ||
const arr = []; | ||
for (let n = 0; n < (groups > 0 ? groups : 1); n++) { | ||
arr.push(...this.emojis); | ||
} | ||
pool.push(...this.shuffle(arr)); | ||
this.firstEmoji = pool[pool.length - 1]; | ||
emojisClone.addEventListener( | ||
'transitionend', | ||
function () { | ||
this.querySelectorAll('.emoji').forEach((emoji, index) => { | ||
if (index > 0) this.removeChild(emoji); | ||
}); | ||
}, | ||
{ once: true } | ||
); | ||
} | ||
for (let i = pool.length - 1; i >= 0; i--) { | ||
const emoji = document.createElement('div'); | ||
emoji.classList.add('emoji'); | ||
emoji.style.width = spinner.clientWidth + 'px'; | ||
emoji.style.height = spinner.clientHeight + 'px'; | ||
emoji.textContent = pool[i]; | ||
emojisClone.appendChild(emoji); | ||
} | ||
emojisClone.style.transitionDuration = `${duration > 0 ? duration : 1}s`; | ||
emojisClone.style.transform = `translateY(-${spinner.clientHeight * (pool.length - 1)}px)`; | ||
spinner.replaceChild(emojisClone, emojis); | ||
}, | ||
randomEmoji: function () { | ||
return this.emojis[Math.floor(Math.random() * this.emojis.length)]; | ||
}, | ||
spin: async function() { | ||
this.init(false, 1, 2); | ||
await new Promise((resolve) => setTimeout(resolve, 1)); | ||
const emojis = document.getElementById('emojis'); | ||
emojis.style.transform = 'translateY(0)'; | ||
}, | ||
shuffle: function ([...arr]) { | ||
let m = arr.length; | ||
while (m) { | ||
const i = Math.floor(Math.random() * m--); | ||
[arr[m], arr[i]] = [arr[i], arr[m]]; | ||
} | ||
return arr; | ||
} | ||
}" | ||
x-init="init()" | ||
class="flex items-center my-6 space-x-1 text-lg text-gray-800" | ||
> | ||
<span>Made with </span> | ||
|
||
<button | ||
id="spinner" | ||
@click="spin" | ||
class="w-12 h-40 overflow-hidden text-xl" | ||
> | ||
<div | ||
id="emojis" | ||
class="flex flex-col items-center justify-center transition-transform duration-1000 ease-in-out" | ||
></div> | ||
</button> | ||
|
||
<span> | ||
in Chicago by | ||
<a class="font-semibold text-violet-800 hover:text-violet-600" href="https://www.jordanwelch.com">Jordan Welch</a> | ||
</span> | ||
</div> | ||
<div id="made-with"></div> |