简体   繁体   English

点击后,模糊我的内容

[英]On click, blur my content behind

Is there a way when I click my menu button (and menu is revealed) my content in the background has a blur on it and when clicked again, the content goes back to normal? 当我单击菜单按钮(并显示菜单)时,有什么方法可以使背景中的内容模糊,再次单击该内容可以恢复正常吗?

Currently working with this HTML: 目前正在使用此HTML:

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

This CSS: 此CSS:

$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 JS: 这个JS:

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


});

I would be very grateful if anyone could help. 如果有人可以帮助,我将不胜感激。 Cheers 干杯

Demo here . 演示在这里

Basically you just need to append a dynamic div (or insert manually) and set give it a fixed position with width: 100% and height: 100% with a background & opacity . 基本上,您只需要追加一个动态div(或手动插入)并设置其fixed位置, width: 100%height: 100%并带有background & opacity

However it must be outside of the .menu container or your .menu contents will also have an opacity. 但是,它必须位于.menu容器之外,否则您的.menu内容也将不透明。

Example on codepen here including: 此处关于codepen的示例包括:

content {filter:blur(5px);

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

This example blurs the content behind, however the browser support for this isn't complete ( http://caniuse.com/#search=filter ) no ie 此示例模糊了后面的内容,但是浏览器对此功能的支持不完整( http://caniuse.com/#search=filter )否

But, you could use just an opaque filter - I have included this in the example) and better browsers get the blur - or for more support use an inline blurred SVG, or maybe a js effect such as http://blurjs.com/ 但是,您可以只使用不透明的滤镜-我已在示例中添加了它),更好的浏览器会模糊-或为获得更多支持,请使用内联模糊SVG,或者使用js效果,例如http://blurjs.com/

You can always search http://css-tricks.com for stylesheet related help as they have a good library. 您可以随时在http://css-tricks.com上搜索样式表相关的帮助,因为它们具有良好的库。

You should be looking at the CSS FILTERS to create the blur effect upon clicking the menu and then turning it back to normal on release. 您应该查看CSS滤镜以在单击菜单后创建模糊效果,然后在发布时将其恢复为正常。

I had this link in my library that clearly shows what you are trying to do JSFIDDLE EXAMPLE 我的库中有此链接,该链接清楚地显示了您正在尝试执行的操作JSFIDDLE示例

and here part of the stylesheet where you have the blur 这是样式表的一部分

This class is added to the container 
(#blurMe) 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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM