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

136
Views
Haciendo un botón para controlar la imagen de fondo en Javascript

Estoy tratando de hacer un botón que puedas presionar en la página web que cambiará su fondo con un gif de nieve que preparé. Obtuve el botón para mostrar y ocultar el gif e incluso agregarlo, pero parece que no puedo hacer que cambie el fondo completo para que parezca que comenzó a nevar. Aquí está el código para eso:

 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"; } }

En este momento, solo tengo el gif oculto en la página hasta que lo necesite. Si alguien puede indicarme la dirección correcta, si puedo lograr esto con Javascript o no, o si debería buscar más a fondo.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

cambia esto

 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"; }

a

 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"; }

por favor dime si eso funciona

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!