如何通过css模糊除当前悬停以外的所有图像

时间:2016-05-07 03:39:29

标签: javascript html css

是否有纯粹的css方法来模糊所有图像,除了正在上面的图像?我当前的代码显示在以下链接中。我有一个模糊区域的包裹,但是不能让图像悬停在不模糊的地方!

谢谢!

基本概念:

.wrap:hover
   {
   -webkit-filter: blur(13px);
    -moz-filter: blur(13px);
    -o-filter: blur(13px);
    -ms-filter: blur(13px);
    filter: blur(13px);  

}

img:hover
{
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-o-filter: blur(0px);
-ms-filter: blur(0px);
filter: blur(0px);  

}  

找到完整代码

https://jsfiddle.net/0q00jorc/2/ *编辑

基本上,我试图模糊所有图像,除了我正在盘旋的一个图像,如果我不在图像上,则不会模糊任何图像。下面答案中的代码就是这样做的,除非它模糊了所有图像,如果我将鼠标悬停在图像之间包含空格的包裹上。我不想模糊,除非我自己在图像上。

2 个答案:

答案 0 :(得分:4)

将模糊效果放在图像上,然后使用img悬停覆盖模糊。

body {
   margin: 0;
   padding: 0;
   background: #EEE;
   font: 10px/13px 'Lucida Sans',sans-serif;
}
.wrap {
   overflow: hidden;
   margin: 10px;
}
.box {
   float: left;
   position: relative;
   width: 20%;
   padding-bottom: 20%;
}
.boxInner {
   position: absolute;
   left: 10px;
   right: 10px;
   top: 10px;
   bottom: 10px;
   overflow: hidden;
}
.boxInner img {
   width: 100%;
  outline: 15px solid rgba(0,0,0,.5);
  outline-offset: -15px;
}
.boxInner .titleBox {
   position: absolute;
   bottom: 0;
   left: 0;
   right: 0;
   margin-bottom: -50px;
   background: #000;
   background: rgba(0, 0, 0, 0.5);
   color: #FFF;
   padding: 10px;
   text-align: center;
   -webkit-transition: all 0.3s ease-out;
   -moz-transition: all 0.3s ease-out;
   -o-transition: all 0.3s ease-out;
   transition: all 0.3s ease-out;
}

.wrap:hover img
{
   -webkit-filter: blur(13px);
    -moz-filter: blur(13px);
    -o-filter: blur(13px);
    -ms-filter: blur(13px);
    filter: blur(13px);  
  
}

.wrap:hover img:hover
{
   -webkit-filter: blur(0px);
    -moz-filter: blur(0px);
    -o-filter: blur(0px);
    -ms-filter: blur(0px);
    filter: blur(0px);  
}
}

body.no-touch .boxInner:hover .titleBox, body.touch .boxInner.touchFocus .titleBox {
   margin-bottom: 0;
}
@media only screen and (max-width : 480px) {
   /* Smartphone view: 1 tile */
   .box {
      width: 100%;
      padding-bottom: 100%;
   }
}
@media only screen and (max-width : 650px) and (min-width : 481px) {
   /* Tablet view: 2 tiles */
   .box {
      width: 50%;
      padding-bottom: 50%;
   }
}
@media only screen and (max-width : 1050px) and (min-width : 651px) {
   /* Small desktop / ipad view: 3 tiles */
   .box {
      width: 33.3%;
      padding-bottom: 33.3%;
   }
}
@media only screen and (max-width : 1290px) and (min-width : 1051px) {
   /* Medium desktop: 4 tiles */
   .box {
      width: 25%;
      padding-bottom: 25%;
   }
}
<div class="wrap">
    
  <!-- Define all of the tiles: -->
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/7.jpg" />
      <div class="titleBox">Butterfly</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/1.jpg" />
      <div class="titleBox">An old greenhouse</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/2.jpg" />
      <div class="titleBox">Purple wildflowers</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/3.jpg" />
      <div class="titleBox">A birdfeeder</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/10.jpg" />
      <div class="titleBox">Crocus close-up</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/4.jpg" />
      <div class="titleBox">The garden shop</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/5.jpg" />
      <div class="titleBox">Spring daffodils</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/6.jpg" />
      <div class="titleBox">Iris along the path</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/8.jpg" />
      <div class="titleBox">The garden blueprint</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/9.jpg" />
      <div class="titleBox">The patio</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/11.jpg" />
      <div class="titleBox">Bumble bee collecting nectar</div>
    </div>
  </div>
  <div class="box">
    <div class="boxInner">
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/12.jpg" />
      <div class="titleBox">Winding garden path</div>
    </div>
  </div>
  
</div>

答案 1 :(得分:1)

~ $ curl -v https://soundcloud.com/dengue/sets/nuevos-sonidos
*   Trying 68.232.44.127...
* Connected to soundcloud.com (68.232.44.127) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: *.soundcloud.com
* Server certificate: GlobalSign Domain Validation CA - SHA256 - G2
* Server certificate: GlobalSign Root CA
> GET /dengue/sets/nuevos-sonidos HTTP/1.1
> Host: soundcloud.com
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: private, max-age=0
< Content-Type: text/html
< Date: Sat, 07 May 2016 03:42:20 GMT
< Server: am/2
< Set-Cookie: sc_anonymous_id=363279-961735-991413-425081; path=/; expires=Tue, 05 May 2026 03:42:20 GMT; domain=.soundcloud.com
< Via: sssr
< X-Frame-Options: SAMEORIGIN
< Content-Length: 47003
<