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

125
Views
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 answers
Answer question

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 Report
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!