Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda