Created
July 19, 2023 23:48
-
-
Save simonw/c3ab94911f42bbd0822ca4e61eb8424e to your computer and use it in GitHub Desktop.
Rotating emoji globe
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Globe Emoji Animation</title> | |
<style>h1 { font-size: 70vh; text-align: center; padding: 0; margin: 0 }</style> | |
</head> | |
<body> | |
<h1>π</h1> | |
<script> | |
const globeEmojis = ['π', 'π', 'π']; | |
const h1 = document.querySelector('h1'); | |
let i = 0; | |
setInterval(() => { | |
h1.innerHTML = globeEmojis[i++ % globeEmojis.length]; | |
}, 500); | |
</script> | |
</body> | |
</html> |
Author
simonw
commented
Jul 19, 2023
Neato. Here's same thing in a React component.
import React, { useState, useEffect } from "react";
export const RotatingGlobe = (props: { className?: string }) => {
const globeEmojis = ["π", "π", "π"];
const [currentGlobe, setCurrentGlobe] = useState(globeEmojis[0]);
useEffect(() => {
let i = 0;
const interval = setInterval(() => {
setCurrentGlobe(globeEmojis[i++ % globeEmojis.length]);
}, 1000);
return () => clearInterval(interval); // Cleanup interval on unmount
}, []);
return <div className={`${props.className}`}>{currentGlobe}</div>;
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment