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

126
Vistas
Making a button to control the background image in Javascript

I'm trying to make a button you can press on the webpage that will change its background with a snow gif I prepared. I got the button to show and hide the gif and even append it, but can't seem to make it change the full background to make it seem like it started snowing. Here's the code for that:

function snowing(){
            let x = document.getElementById('hideimage');
            document.getElementById('sno_btn').onclick = function(){
                if (x.style.display === "none") {
                    x.style.display = "block";
                    document.body.style.backgroundImage = "url('snow.gif') no repeat scroll center";
                } else {
                    x.style.display = "none";
                    document.body.style.background = "black";
                }
        }

Right now, I just have the gif hidden on the page until I need it. If someone can point me in the right direction, if I can achieve this with Javascript or not, or if I should be looking deeper?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

change this

if (x.style.display === "none") {
                x.style.display = "block";
                document.body.style.backgroundImage = "url('snow.gif') no repeat scroll center";
            } else {
                x.style.display = "none";
                document.body.style.background = "black";
            }

to

if (getComputedStyle(x).display === "none") {
                x.style.display = "block";
                document.body.style.background = "url('snow.gif') no repeat scroll center";
            } else {
                x.style.display = "none";
                document.body.style.background = "black";
            }

pls tell me if that works

about 4 years ago · Juan Pablo Isaza Denunciar
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