Clicking will cause my background content to blur

Is there a way to implement a menu button that, when clicked, reveals a menu with blurred content in the background? And when clicked again, the content returns to normal?

Here's the current HTML structure:

<div class="menu">
  <div class="line"></div>
  <nav>
    <ul>
      <li><a target="_parent" href="">A</a></li>
      <li><a target="_parent" href="">B</a></li>
      <li><a target="_parent" href="">C</a></li>
      <li><a target="_parent" href="">D</a></li>
    </ul>
  </nav>
</div>

The CSS styling used:

$square: 50px;
* {
  @include box-sizing(border-box);
}
body {
  background: #111;
  font: 300 14px Consolas, system, monospace;
  color: #fff;
}
.menu {
  position: fixed; 
  height: $square;
  width: $square;
  cursor: pointer;
  top: 0;
  right: 0;
  background: #fff;
  @include transition(all 250ms ease-in-out);
  z-index: 100;
  overflow: hidden;
  nav {
    position: fixed;
    left: 50%;
    top: 50%;
    @include transform(translateY(-50%) translateX(-50%));
    opacity: 0;
    @include transition(all 250ms linear 250ms);
    pointer-events: none;
    ul {
      list-style-type: none;
      padding: 0;
      li a {

        display: block;
        padding: 10px;
        text-decoration: none;
        color: #000;
        text-align: center;
        &:hover {
          background: #000;
          color: #fff;
        }
      }
    }
  }
  .line {
    height: 5px;
    width: $square - 10;
    background: #000;
    position: absolute;
    top: ($square/2)-(5/2);
    left: ($square - ($square - 10))/2;
    @include transition(all 250ms linear);
    &:after, &:before {
      content: ' ';
      height: 5px;
      width: $square - 10;
      background: #000;
      position: absolute;
      @include transition(all 250ms linear);
    }
    &:before {
      top: -10px;
    }
    &:after {
      bottom: -10px;
    }
  }
  &.active {
    width: 100%;
    height: 100%;
    nav {
      opacity: 1;
      pointer-events: all;
    }
    .line {
      background: transparent;
      &:before {
        background: #000;
        @include transform(rotate(-405deg));
        top: 0px;
      }
      &:after {
        background: #000; 
        @include transform(rotate(405deg));
        bottom: 0px;
      }
    }
  }
}

This JavaScript functionality is included:

$('.menu').click(function(){
  $this = $(this);
  if ($this.hasClass('active')) {
    $this.removeClass('active');
  }
  else {
    $this.addClass('active');    
  }


});

Your assistance on this matter would be greatly appreciated. Thank you.

Answer №1

Check out this demo on CodePen showcasing:

content {filter:blur(5px);

http://codepen.io/simoncmason/pen/ogoPXK

In this example, the content is blurred in the background. Keep in mind that browser support for this feature may not be complete (http://caniuse.com/#search=filter) especially in Internet Explorer.

Alternatively, you can apply an opaque filter for broader support while allowing better browsers to experience the blur effect. Another option is using an inline blurred SVG or implementing a JavaScript library like Blur.js

Answer №2

Check out the demonstration here.

In essence, all you have to do is add a dynamic div (or insert manually) and give it a fixed position with width: 100% and height: 100%, along with a specified background & opacity.

Remember to ensure that this div is positioned outside of the .menu container, as placing it within will cause the .menu contents to inherit the opacity.

Answer №3

For all your stylesheet related inquiries, a great resource to explore is http://css-tricks.com, known for its extensive library.

To achieve the desired blur effect when clicking on the menu and reverting it back to normal upon release, focus on utilizing CSS FILTERS.

If you need a visual demonstration of this technique, check out this helpful JSFIDDLE EXAMPLE I came across in my research.

Incorporate the following snippet into your stylesheet to implement the blur effect:

This specific class (#blurMe) is assigned to the container when the sidebar is open.
-----------------------------------*/
.blurred {
  -webkit-transition: all 0.6s ease;
  transition: all 0.6s ease;
  -webkit-filter: blur(10px);
  filter: blur(10px);
  -webkit-filter: url(#blur);
          filter: url(#blur);
  filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='10');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring the existence of a MySQL database prior to executing a Node.js application

I am currently working on a Node.js/Express application that communicates with a MySQL server using Sequelize. I want to make sure that a particular database is created before the app starts running when using npm start. I think I need to create a one-ti ...

Clicking on a link in HTML with the onclick event

I am looking to create a button that will direct me to a different page. Here is the code snippet I have: <div align="right" ><input type="submit" id="logout" onclick="location.href='/login?dis=yes'" value="Sign Out" ></div>& ...

When a table undergoes a dynamic reload, the formatting for the columns fails to display properly

After fetching image metadata from an API call, a table is dynamically generated on page load. Subsequently, when new images are uploaded, the function responsible for building the table is called again to include this new data. However, despite the CSS st ...

Using Jquery and AJAX to display results during the execution of a time-consuming operation in PHP

Good day. I am experiencing an issue with my code where, upon submission, data is sent to a PHP file that checks the health status of multiple network nodes. The problem I am facing is that it takes around 40 seconds for the tasks to complete and during t ...

Obtaining a pdf file using javascript ajax is a straightforward process

Looking to access my JavaScript file generated by a microservice (byte[]): public int retrieveLabel(Request request, Response response) throws IOException { response.header("Access-Control-Allow-Origin", "*"); ArrayList<JSONObject> orders = ...

Can someone explain why the min-width property is not being respected by the <input> element?

Visit this link for the code The text field in the provided link should only be 10px wide but it is currently displaying a width of 152px. Here is the code snippet: .input { width: 100%; box-sizing: border-box; } .cont { padding: 2px; } .main ...

How can I submit text or HTML content using Jquery ajax on Tumblr?

I have recently registered my application on Tumblr and I am trying to post data from my website. I have implemented the following JavaScript code, but unfortunately it doesn't seem to be working properly even though I am receiving a success message. ...

Is there a way to extract shared properties within a Material UI style declaration?

I am working with a specific set of style rules that define different statuses: status_in_progress: { fontSize: 14, backgroundColor: theme.palette.success.dark, padding: 2, paddingLeft: 5, paddingRight: 5, display: "inline-bl ...

Struggling to attach a click event to a duplicated element with jquery

I was attempting to add a click event to a cloned object with the following sample code, but for some reason I couldn't get it to work. Despite multiple attempts, attaching the click event to the object proved challenging. Take a look at the code and ...

Instructions on how to redirect to an external website once the ajax request data has been successfully retrieved

Currently working on the following code snippet... <script> $("#ajaxform").submit(function(e) { $("#simple-msg").html("<img src='images/ajax-loader.gif'/>"); var postData = $(this).serializeArray(); var formURL = $(this). ...

How can I make sure certain properties in the Vuex store don't retain their state after a redirect during server-side rendering (SSR)?

Our approach involves server-side rendering with the use of preserveState to persist all vuex modules' state when navigating between pages. However, we have a specific store where we need to exclude certain properties from persistence. Is there a sol ...

Continuous horizontal columns

Is there a way to create horizontal columns with inline-blocks, like the method described here, without having vertical gaps between items on the second line due to different heights? I want to eliminate the vertical gaps between the tiles using only CSS. ...

Dividing the z-index by half of the shape

I am trying to achieve the following shape: https://i.stack.imgur.com/Lr9gv.png So far, I have attempted the following code. How can I combine these elements together? .clal-loader{ display:flex; } .clal-loader div{ border: 10px solid #38477e; b ...

Having trouble detecting the Selection event of a Dropdown List upon loading

When a user chooses an option from the dropdown menu, I need to capture the selected item and perform an action: $("#user-list").on("change", function() { var selectedUser = $(this).find(":selected").text(); // Perform action with the selected us ...

Leverage shared techniques and libraries across two different projects

I have a NodeJS project set up on Firebase cloud functions, with our backend service (ExpressJS) as an HTTP function and some cron functions. The project structure looks like this: /project (the main directory for all cloud functions) - package.json ...

Create a basic cache within an AngularJS service to store data retrieved from HTTP requests, ensuring that the cache returns an object

Looking to implement a simple caching mechanism in an AngularJS service for data retrieved from HTTP requests. The goal is to always reference the same object to avoid duplicating requests. Below is an example code snippet showcasing the issue at hand. Li ...

Store the checkbox's data in the database for safekeeping

Hey there, I'm working on saving the value of a checkbox using PHP. The twist is that the value is generated through JavaScript. How can I handle this scenario and save the value using PHP? Checkbox: <input type='checkbox' name='ca ...

Using JavaScript variables within an @if statement in Laravel within the innerHTML segment

How can I incorporate a JavaScript variable 'x' into an @if statement in Laravel? I have tried placing it both inside and outside of the @if statement. When placed outside, it works perfectly fine, but I really need to perform an action based on ...

What is the preferred convention for defining AngularJS directives as "attributes" versus "elements"?

When creating Angular directives, I've noticed that some directives could also be defined as either an HTML element or an attribute. I'm curious to know what the community convention is for choosing between the two, and the reasons behind it. Fo ...

Converting a Class Component to a Functional Component: Step-by-Step Guide

Recently, I have been transitioning from working on class components to function components in React. However, I am facing some issues with my functional component code after converting it from a class component. In my functional component code, there is ...