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
Javascript Blur background when div is block?

I'm having a problem with bluring the background when my menu is open. I tried writing something on my own but it's not working.

function backgroundBlur() {
  var menuBox = document.getElementById("mobile-menu");
  var blur = document.getElementById("body");
  if (menuBox.style.dsiplay = "block") {
    blur.style.filter = "blur(3px)";
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think the problem can be caused by three reasons:

  • Typo noted by @RyanWalls
  • The backgroundBlur() method is not called
  • The display property of the menuBox is not block

I made a run to simulate this event:

let button = document.getElementById('setBlur');
let control = false;

function backgroundBlur(control) {
  var menuBox = document.getElementById("mobile-menu");
  var blur = document.getElementById("body");
  
  if (menuBox.style.display === "block")
  {
    if(!control)
    {
      blur.style.filter = "blur(3px)";
      button.innerHTML = 'Remove Blur';
    }
    else
    {
      blur.style.filter = "blur(0px)";
      button.innerHTML = 'Add Blur';
    }
  }
}

button.addEventListener('click', function() {
    backgroundBlur(control);
    control = !control;
});
*{
  margin: 0;
}
#body{
  background-color: black;
}
button{
  margin-top: 25px;
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  width: 100%;
}
.vertical-menu {
  width: 200px;
}
.vertical-menu a {
  background-color: #eee;
  color: black;
  display: block;
  padding: 12px;
  text-decoration: none;
}
.vertical-menu a:hover {
  background-color: #ccc;
}
.vertical-menu a.active {
  background-color: #04AA6D;
  color: white;
}
<div id="body">
  <div id="mobile-menu" style="display: block;">
    <div class="vertical-menu">
      <a href="#" class="active">Home</a>
      <a href="#">Link 1</a>
    </div>
  </div> 
</div>

<button id="setBlur">Add Blur</button>

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