I’m trying to change my site(Which is not published yet) color background when I toggle with button and when I toggle it again it turns back to the original color but unfortunately when I toggle the button the background color changes to the gray and toggle back it gets darker(but doesn’t get back to the original color which is :E5F0FE)Please take a close look at the code and let me know what my issue is!
The problem might be with the 1px image that dummyimage returns.
You can create a 1px image (or more. 1px is just to save some loading time, but other small images are also good enough) with the color E5F0FE, upload it to the site through the media manager, and use its URL instead.
I’ve created a 1px image with the color E5F0FE and uploaded on my media manager and link it(Please see the code) according to what you recommended me to do and thank you very much Please see the screenshot in dark mode the font color changes but the icons color(which is pointed by white arrows) is dark blue how can I have them like text fonts or a little lighter?
In this case what you should do is like that.
In the masterPage.js:
import wixSite from 'wix-site';
$w.onReady(function () {
const currentPath = wixSite.currentPage?.url;//it will show you an error red line on the editor - you should ignore it.
$w('#darkModeSwitch').onChange(function () {
if ($w('#darkModeSwitch').checked) {
$w('Document').background.src = 'https://dummyimage.com/1/333333';
$w('#darkModeState').text = 'Dark Mode On';
if(currentPath === '/my-page-path'){
$w('#emailIcon').src = 'https://static.wixstatic.com/media/d04120_2cd897ba7a2246a396bfa8a23dad40ef~mv2.png'; //it will show you an error red line on the editor - you should ignore it.
}
} else {
$w('Document').background.src = "https://static.wixstatic.com/media/d04120_2636c2ad09774cd597ccfb1e9f929e25~mv2.png";
$w('#darkModeState').text = 'Dark Mode Off';
if(currentPath === '/my-page-path'){
$w('#emailIcon').src = 'https://static.wixstatic.com/media/d04120_a2f9e9ccd89744d5af2cd1e4bb652e6b~mv2.jpg'; //it will show you an error red line on the editor - you should ignore it.
}
}
});
});
This will only work if you toggle the switch when you’re on the current page.
If you wish to keep the mode across all the site pages, you keep the mode in the session/locale browser cache and apply it on page load.
Thanks J.D. for your response could you kindly inform me what to add in red option of the code please?
as for this “you keep the mode in the session/locale browser cache and apply it on page load”. I didn’t get it could you kindly elaborate it please?
The reason I put the code in the homepage because when I put the code in masterPage.js I get the error because emailIcon doesn’t exist Please see the screenshot
When I toggle on the button in preview work page gets dark but when I publish the site and try it that page doesn’t change.If you play with it for example if you go to about page and toggle the button it gets dark(except middle of the page which won’t change)and then go to work page and toggle the button then get back to work page again and toggle the button the dark mode won’t work!
Please see the video screen and you will get exactly what I mean!
@jonatandor35 I visited the link you provided with thank you for that I saw some code regarding Store an item in memory storage and Retrieve an item from session storage should I copy and paste the code in masterPage.js?