Skip to content

Instantly share code, notes, and snippets.

@artzub
Created January 10, 2021 06:05
Show Gist options
  • Save artzub/3f2ea3932801d13a1c1fde402f407236 to your computer and use it in GitHub Desktop.
Save artzub/3f2ea3932801d13a1c1fde402f407236 to your computer and use it in GitHub Desktop.
const translate = (x, y) => `transform: translate(${x}px, ${y}px)`;
const show = (element) => {
const rect = element?.getBoundingClientRect();
let opacity = 0;
if (rect) {
opacity = 1;
leftTop.setAttribute('style', translate(rect.left, rect.top));
leftBottom.setAttribute('style', translate(rect.left, rect.bottom));
rightTop.setAttribute('style', translate(rect.right, rect.top));
rightBottom.setAttribute('style', translate(rect.right, rect.bottom));
}
overlay.setAttribute('style', `opacity: ${opacity}`);
};
const hide = () => {
show();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment