Created
March 28, 2022 16:16
-
-
Save viktor-yakubiv/0ac7f051303140a629c03365eb7a3000 to your computer and use it in GitHub Desktop.
SVG sprite boilerplate
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 xmlns="http://www.w3.org/2000/svg"> | |
<symbol id="name" viewBox="0 0 24 24"> | |
<!-- icon code goes here --> | |
</symbol> | |
<!-- The script makes the targeted icon visible when the file opened in the browser tab --> | |
<script> | |
const useElement = document.createElementNS(document.rootElement.namespaceURI, 'use') | |
const render = () => useElement.setAttribute('href', location.hash) | |
document.rootElement.append(useElement) | |
window.addEventListener('hashchange', render) | |
render() | |
</script> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment