Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda