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

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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