-
-
Save uhyo/d52ca650225a4c34b55b60312f9d1a16 to your computer and use it in GitHub Desktop.
Googleの大統領選の結果の州をクリックすると色を変えられるやつ2020
This file contains 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
(()=>{ | |
const svg = document.querySelector('svg.vlmbi.H21Mnd'); | |
const svg2 = cl(svg); | |
const paths = svg2.querySelectorAll('path.xH0v4d'); | |
const cs = [ | |
'rgb(218, 220, 224)', | |
'rgb(0, 155, 216)', | |
'rgb(166, 220, 241)', | |
'rgb(241, 176, 180)', | |
'rgb(219, 29, 40)', | |
]; | |
for (let i=0, l=paths.length; i<l; i++){ | |
const p = paths[i]; | |
p.addEventListener('click', e=>{ | |
const f = p.style.fill; | |
const i = cs.indexOf(f); | |
p.style.fill = cs[(i+1)%cs.length]; | |
}, false); | |
} | |
function cl(svg){ | |
const re = svg.getBoundingClientRect(); | |
const svg2 = svg.cloneNode(true); | |
document.body.appendChild(svg2); | |
svg2.style.position='absolute'; | |
svg2.style.left=(re.left+window.pageXOffset)+'px'; | |
svg2.style.top=(re.top+window.pageYOffset)+'px'; | |
svg2.style.zIndex='100000'; | |
return svg2; | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment