From 0498a68f90377b746a379dda01f4a6eb3cb6add9 Mon Sep 17 00:00:00 2001 From: mellodoot Date: Tue, 18 Apr 2023 11:32:11 +0100 Subject: [PATCH] inject css at runtime- no onmouse events! --- prideflag.js | 90 +++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/prideflag.js b/prideflag.js index aabc865..42fc6c9 100644 --- a/prideflag.js +++ b/prideflag.js @@ -7,58 +7,60 @@ */ const pride_flag_svg = -` - - - - - - + ` + + + + + + - - - - - - - - -`; + + + + + + + + + `; + +const pride_flag_css = + `#pride-flag svg { + position: fixed; + top: 0; + right: 0; + width: 120px; + transform-origin: 100% 0%; + transition: transform .5s cubic-bezier(.32,1.63,.41,1.01); + z-index: 8008135; + pointer-events: none; + } + #pride-flag svg:hover { + transform: scale(110%); + } + #pride-flag svg:active { + transform: scale(110%); + } + #pride-flag svg * { + pointer-events: all; + }`; function create_pride_flag() { const container = document.createElement("a"); - container.id = "pride-triangle"; + container.id = "pride-flag"; container.href = "https://github.com/mellodoot/prideflag"; container.target = "_blank"; - - triangle = document.createElement('svg'); - triangle.innerHTML = pride_flag_svg; - triangle.style.position = "fixed"; - triangle.style.top = "0"; - triangle.style.right = "0"; - triangle.style.width = "120px"; - triangle.style.transformOrigin = "100% 0%"; - triangle.style.transition = "transform .5s cubic-bezier(.32,1.63,.41,1.01)"; - triangle.style.zIndex = "8008135"; - - triangle.onmouseenter = function () { - this.style.transform = "scale(110%)"; - }; - triangle.onmouseleave = function () { - this.style.transform = "initial"; - }; - - triangle.onmousedown = function () { - this.style.transform = "scale(90%)"; - }; - triangle.onmouseup = function () { - this.style.transform = "initial"; - }; - - container.appendChild(triangle); - + container.innerHTML = pride_flag_svg; return container; } +function load_pride_flag_style() { + const pride_stylesheet = document.createElement('style'); + pride_stylesheet.textContent = pride_flag_css; + document.head.appendChild(pride_stylesheet); +} + +load_pride_flag_style(); pride_flag = create_pride_flag(); document.body.appendChild(pride_flag); \ No newline at end of file