Skip to content

Instantly share code, notes, and snippets.

@jairusjoer
Created May 19, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jairusjoer/83ed3e1d5669b4b94c04b7b64baf2631 to your computer and use it in GitHub Desktop.
Save jairusjoer/83ed3e1d5669b4b94c04b7b64baf2631 to your computer and use it in GitHub Desktop.
A super simple script to create placeable random stickers with image elements
const sticker = (set: string[], canvas: HTMLElement | null) => {
let z = 0;
if (canvas) {
canvas.onclick = (event: MouseEvent) => {
let randomImage = set[Math.floor(Math.random() * set.length)];
let randomRotation = Math.random() * (45 - -45) + -45
const element = document.createElement('img');
element.ariaHidden = "true";
element.className = 'sticker-item';
element.src = randomImage;
element.style.top = `${event.pageY}px`;
element.style.left = `${event.pageX}px`;
element.style.zIndex = `${z++}`;
element.style.rotate = `${randomRotation.toFixed(2)}deg`;
canvas.appendChild(element);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment