Last active
January 27, 2021 16:44
-
-
Save beatrizsmerino/cf3f2f603b23a4de0df57b08b4e2ba50 to your computer and use it in GitHub Desktop.
Insert file sprites.svg with the icons to the end of the all html files
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
/* | |
* COMPONENTS | |
* sprites | |
* ================================================= | |
*/ | |
/** | |
* @function printSprites | |
* @description Insert file sprites.svg with the icons to the end of the all html files | |
*/ | |
function printSprites() { | |
const url = '../../images/icons/sprites.svg'; | |
const className = 'sprite'; | |
const getContentFile = async(urlFile) => { | |
const getData = await fetch(urlFile); | |
const data = await getData.text(); | |
return data; | |
}; | |
getContentFile(url).then((data) => { | |
const contentSprites = document.createElement('div'); | |
contentSprites.setAttribute('class', className); | |
document.querySelector('body').appendChild(contentSprites); | |
contentSprites.insertAdjacentHTML('beforeend', data); | |
}); | |
} | |
(function() { | |
printSprites(); | |
}()); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title> | |
Sprites | |
</title> | |
</head> | |
<body> | |
<svg class="icon icon-menu"> | |
<use xlink:href="#icon-menu" href="#icon-menu"></use> | |
</svg> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment