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

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

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