Skip to content

Instantly share code, notes, and snippets.

@markvdesign
Last active September 19, 2024 05:56
Show Gist options
  • Save markvdesign/62a60171069e56cf37932665edbce6b3 to your computer and use it in GitHub Desktop.
Save markvdesign/62a60171069e56cf37932665edbce6b3 to your computer and use it in GitHub Desktop.
funwithsvgscript.svg
Display the source blob
Display the rendered blob
Raw
<svg
viewBox="0 0 10 10"
height="120px"
width="120px"
xmlns="http://www.w3.org/2000/svg">
<circle cx="5" cy="5" r="4" />
<script>
// <![CDATA[
function getColor() {
const R = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
const G = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
const B = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
return `#${R}${G}${B}`;
}
document.querySelector("circle").addEventListener("click", (e) => {
e.target.style.fill = getColor();
});
// ]]>
</script>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment