【问题标题】:Blur/Unblur 2 Different Backgrounds on Hover悬停时模糊/取消模糊 2 个不同的背景
【发布时间】:2016-04-24 09:08:38
【问题描述】:

在我的代码中,我将浏览器宽度划分为 2 个 div。我打算为每个 div 应用一个超链接,比如 2 个大按钮,但在此之前,我想对它们应用一些 webkit-filter,这样它们作为一个按钮会更直观。

如何将超链接应用到这些 div 并在悬停时应用模糊/取消模糊而不会使文本模糊?

以下是我目前使用的代码: (图片仅供测试:P)

#containergaleria {
    display: table;
    width: 100%;
}

#containergaleria div {
    display: table-cell;
    width: 50%;
}

#imagens {background-image: url("http://gamerealla.ru/wp-content/uploads/2014/09/1392986721_r1.jpg");
         background-position: right center; 
}

#videos {background-image: url("http://gamehall.uol.com.br/v10/wp-content/uploads/2015/01/Black-Desert-Online-Beast-Master-Woman-02.jpg");
        background-position: left center; 
}


p.centertext {
    margin-top: 25%;
    margin-bottom: 25%
}

body {
    overflow:hidden;
}
<div id="containergaleria">
  
    <div id="imagens"><p class="centertext" align="right"><a class="button-medium pull-center" href="http://stackoverflow.com/" target="_blank">IMAGENS</a>&nbsp;&nbsp;</p></div>
  
    <div id="videos"><p align="left">&nbsp;&nbsp;<a class="button-medium pull-center" href="http://stackoverflow.com/" target="_blank">VÍDEOS</a></p></div>
  
</div>

【问题讨论】:

  • 你想用JS吗?

标签: html css hover webkit blur


【解决方案1】:

查看this post。您不能将模糊滤镜应用于背景图像,只能使用 &lt;img/&gt; 标签。但是,在您的内容下方使用绝对定位的&lt;img/&gt;z-indexed,您可以达到相同的效果。

【讨论】:

  • 我还想指出,模糊图像对手机或低端笔记本电脑等性能较弱的设备尤其不利。请务必在其中一些设备上进行测试,因为为了美观,它们的体验可能会明显变差。您可以通过使用较低分辨率的图像、降低模糊半径或提供预模糊图像来提高性能。
【解决方案2】:

您可以通过在 CSS 上的 :before 元素上使用背景来做到这一点。

#imagens:before,
#videos:before {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
content: "";
transition: all .5s ease;
-webkit-transition: all .5s ease;
filter: blur(0);
-webkit-filter: blur(0);
}

#imagens:hover:before,
#videos:hover:before {
filter: blur(2px);
-webkit-filter: blur(2px);
}

#imagens:before {
background-image: url("http://gamerealla.ru/wp-content/uploads/2014/09/1392986721_r1.jpg");
background-position: right center;
}

#videos:before {
background-image: url("http://gamehall.uol.com.br/v10/wp-content/uploads/2015/01/Black-Desert-Online-Beast-Master-Woman-02.jpg");
background-position: left center;
}

检查以下小提琴: https://jsfiddle.net/k486zf3w/

【讨论】:

  • 哇,非常有用的功能!有人说它可能会对较弱的设备征税,所以我将在我姐姐的笔记本上进行测试! :) 感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-09
  • 1970-01-01
  • 2018-04-24
相关资源
最近更新 更多