Created
January 17, 2020 15:44
-
-
Save oelna/9630eda87fb0ce50a5b29052356ab2c8 to your computer and use it in GitHub Desktop.
SVG with query parameters
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
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="200" height="200" viewBox="0 0 200 200"> | |
<!-- link to external javascript file --> | |
<!--<script xlink:href="game.js"></script>--> | |
<script xmlns="http://www.w3.org/2000/svg" type="text/javascript"><![CDATA[ | |
window.addEventListener('load', function () { | |
const parameters = new URLSearchParams(window.location.search); | |
const colorParameter = parameters.get('color'); | |
const rectElements = document.querySelectorAll('#segments rect'); | |
for (let i = 0; i < rectElements.length; i++) { | |
rectElements[i].style.fill = '#' + colorParameter; | |
} | |
}, false); | |
]]></script> | |
<g id="segments"> | |
<rect x="20" y="40" width="50" height="75" fill="red" /> | |
<rect x="120" y="70" width="100" height="125" fill="blue" /> | |
<rect x="70" y="150" width="40" height="55" fill="green" /> | |
</g> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment