Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Dark mode flashing on squarespace page load

I've been trying to implement a persistent dark mode onto my website on Squarespace. When the user clicks the dark mode, we want to to fade in and out of said mode, and have been using the following CSS/JS to do so:

CSS Snippet:

.dark-mode {
  span {
    color: #fff !important;
    transition: color 0.5s !important;
  }
  .section-background,
  .site-wrapper {
    background-color: #151515 !important;
    transition: background 0.5s !important;
  }
}

JS:

$('.dark-mode-toggle').on('click', function(e) {
  $('body').toggleClass("dark-mode"); //you can list several class names 
  e.preventDefault();
  if (document.body.classList.contains('dark-mode')) { //when the body has the class 'dark' currently
    localStorage.setItem('darkMode', 'enabled'); //store this data if dark mode is on
  } else {
    localStorage.setItem('darkMode', 'disabled'); //store this data if dark mode is off
  }
});

if (localStorage.getItem('darkMode') == 'enabled') {
  document.body.classList.toggle('dark-mode');
  $("i.fas").addClass("fa-sun");
}

I'm aware that this is messy, as I'm still getting used to JS/JQuery, so I'm using a mix of both. When the page loads, however, the page will flash for the specified animation time, as if it has just been clicked. How do I stop this from happening?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!