I am trying to build a masonry portfolio website with a light and dark mode.
I've been following Connor Bailey's "Vanilla JavaScript: Masonry Grid Layout" tutorial. Link to video: https://www.youtube.com/watch?v=MdKDHkhdCto&ab_channel=ConorBailey Link to code: https://github.com/conorbailey90/masonry-grid-layout
I have added a light mode so when my icon is clicked, the colour scheme shifts:
var icon = document.getElementById("icon");
icon.onclick = function(){
document.body.classList.toggle("light-theme");
}
:root {
/* colours */
--backgroundColour: #000000;
--textColour: #ffffff;
--darkGrey: #161616;
}
.light-theme {
--backgroundColour: #ffffff;
--textColour: #000000;
--darkGrey: #a5a5a5;}
/* SVG colours */
.cls-1 {
fill: var(--textColour);
}
This works with every element and I have defined a class in my style.css code so the SVG (that has been defined in my HTML) will change colour as the text does.
The problem comes with my svg content that has not been defined in HTML. The following code is how my images are entered into my masonry grid layout:
const posts = [];
const item0 = ['items/svg-1.svg'];
const images = [
item0,
];
This format works but the SVG in my masonry grid is not dynamically editable. I would like the white part of my svg to turn black when I switch light themes but it seems like there is not a way of doing this using my current reference mechanism.
Is there a different way I can reference my SVG files so that they can be modified dynamically in CSS like my other icon?
problem: When I click my "light mode" button I hoped the white parts of my SVG files would turn black (because of my defined --text-colour variable).
The text & svg defined in HTML did follow the --text-colour variable The svg defined in javascript did NOT follow the --text-colour variable.