javascript - 悬停时隐藏背景层,悬停在 <p> 元素上时收割

标签 javascript html css

我正在使用 mixitup 库创建一个可排序的网格。我在单个网格项 (.mix) 之上有一个覆盖网格项 (.image-over)。当将鼠标悬停在网格元素上时,背景中的 div(带有背景图像)变得模糊(.mix)并且显示的文本被隐藏(h1)。在覆盖的 div 中显示一个新文本 (p.descfirst)。当我将鼠标悬停在

中的新文本上时,文本重新出现 (h1)。关于如何避免这种情况有什么建议吗?

.mix,
.gap {
  display: inline-block;
  vertical-align: top;
}

.mix {
  background: #fff;
  margin-bottom: 1rem;
  position: relative;
  -webkit-filter: grayscale(0) blur(0);
  filter: grayscale(0) blur(0);
  transition: .4s ease-in-out;
  z-index: -1;
}

.image-over:hover .mix {
  position: relative;
  -webkit-filter: grayscale(100%) blur(2px);
  filter: grayscale(100%) blur(2px);
  transition: .1s ease-in-out;
}

.image-over {
  display: inline-block;
  position: relative;
  top: 0;
  z-index: 600;
  background: transparent;
}

.mix:before {
  content: '';
  display: inline-block;
  padding-top: 100%;
}

.mix h1 {
  font-weight: 1600;
  font-size: 500em;
  color: #fff;
  position: absolute;
  z-index: 2;
  top: 0;
  margin: 0 auto;
  padding: 5px;
  background: rgba(0, 0, 0, 0.3);
}

.mix:hover h1 {
  display: none;
}

.image-over:hover>p.descfirst {
  position: absolute;
  top: 40px;
  left: 40px;
  color: #ffffff;
  font-size: 16px;
  font-weight: bold;
  z-index: 1;
  transition: .2s ease-in-out;
  line-height: 25px;
  margin: 0;
}
<div class="container">
  <a href="./show.html">
    <div class="image-over">
      <p class="descfirst">Progressive</p>
      <div class="mix pink large square" style="background: url('./img/night.jpg')">
        <h1>3 | Test</h1>
      </div>
    </div>
  </a>
</div>

更新

由于运行片段示例在此处并没有真正发挥作用,因此提供了一些屏幕截图来演示该问题。

Normal Grid styling with no mouse over On hover background image gets blurred, new <p> text appears When hovering over <p> element the h1 from underlying area reappears - I want to avoid this

最佳答案

我会在 mouseenter 事件中使用一点点 jquery 而不是 css。

https://api.jquery.com/mouseenter/

$( "#outer" ).mouseenter(function() {
    $( "#inner" ).doStuffHere();
});

关于javascript - 悬停时隐藏背景层,悬停在 <p> 元素上时收割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45282647/

相关文章:

javascript - jquery, mouseenter 下移图片

jquery - 光滑的 slider : How to set arrows inside and not outside?

jQuery .animate() 和带有固定元素的 css 位置

jQuery addClass 高度问题

javascript - PHP中显示AJAX函数返回的多个值时出错

javascript - 如何使用 jQuery 的scroll() 事件在每个像素移动时执行函数

javascript - 使用两个变量的内容并将其作为一个变量使用

php - 如何使用nginx重定向同一目录下的多个文件?

javascript - 如何使用 Javascript 以通用方式从多个 html 元素中获取值

jquery - 从顶部而不是从底部的 SVG 动画