覆盖中的CSS链接接管div

时间:2017-09-15 19:22:19

标签: javascript jquery html css

我有一个包含链接的<div>

<div>的右下角,我有一个覆盖元素,在悬停时会占据整个<div>

此叠加元素还包含一个链接。

我的问题是覆盖元素中的链接不可点击。

问题是因为我在类pointer-events: none;上使用.overlay-content,但如果我不使用它,则两个链接都会死亡。

请在此处查看代码:

.panel-default1 {
  padding-top: 10px;
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.10);
  height: 400px;
  width: 400px;
  overflow: hidden;
  margin: 0 auto;
  position: relative;
}

.amg-corner-button_wrap {
  display: block;
  background-color: #e8c63d;
  position: absolute;
  transform: rotate(45deg);
  right: -320px;
  bottom: -320px;
  width: 400px;
  height: 400px;
  -moz-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  -webkit-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out;
}

.amg-corner-button_wrap:hover {
  transform: rotate(45deg) scale(4);
}

.overlay-content {
  pointer-events: none;
  bottom: 0;
  color: #333;
  left: 0;
  opacity: 0;
  padding: 30px;
  position: absolute;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  right: 0;
  top: 0;
  -moz-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

.overlay-content h2 {
  border-bottom: 1px solid #333;
  padding: 0 0 12px;
}

.amg-corner-button_wrap:hover~.overlay-content {
  opacity: 1;
  -moz-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
  -moz-transition-delay: 0.3s;
  -o-transition-delay: 0.3s;
  -webkit-transition-delay: 0.3s;
  transition-delay: 0.3s;
}
<div class="panel panel-default1">
  <div class="panel-body">
    <a href="#">Link</a>
    <div class='amg-corner-button_wrap'></div>

    <div class="overlay-content">
      <h2>Image Ink Logo</h2>
      <a href="#">Link</a>
    </div>

  </div>
  <!-- panel body -->

</div>
<!-- panel default -->

另外,here is fiddle

有什么方法可以实现这个目标吗?

4 个答案:

答案 0 :(得分:2)

无法相信我实际上找到了一个没有任何缺点的纯CSS解决方案。

&#13;
&#13;
.panel-default1 {
  padding-top: 10px;
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.10);
  height: 400px;
  width: 400px;
  overflow: hidden;
  margin: 0 auto;
  position: relative;
}

.amg-corner-button_wrap {
  display: block;
  background-color: #e8c63d;
  position: absolute;
  transform: rotate(45deg);
  right: -320px;
  bottom: -320px;
  width: 400px;
  height: 400px;
  -moz-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  -webkit-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out;
}

.wrap:hover .amg-corner-button_wrap {
  transform: rotate(45deg) scale(4);
}

.overlay-content {
  pointer-events: none;
  bottom: 0;
  color: #333;
  left: 0;
  opacity: 0;
  padding: 30px;
  position: absolute;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  right: 0;
  top: 0;
  -moz-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

.overlay-content h2 {
  border-bottom: 1px solid #333;
  padding: 0 0 12px;
}

.wrap:hover .amg-corner-button_wrap ~ .overlay-content {
  pointer-events: auto;
  opacity: 1;
  -moz-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
  -moz-transition-delay: 0.3s;
  -o-transition-delay: 0.3s;
  -webkit-transition-delay: 0.3s;
  transition-delay: 0.3s;
}
&#13;
<div class="panel panel-default1">
   <div class="panel-body">
     <a href="#">Link</a>
     <div class="wrap">
        <div class='amg-corner-button_wrap'></div>
        <div class="overlay-content">
          <h2>Image Ink Logo</h2>
          <a href="#">Link</a>
        </div>
    </div>
  </div> <!-- panel body -->
</div> <!-- panel default -->
&#13;
&#13;
&#13;

JSFiddle

不是在角落按钮上听:hover事件,而是在父元素上听它。因为:hover将被分派,而不管元素的鼠标交互如何。孩子们,一旦角落按钮被悬停,就可以将pointer-events: auto设置为包含链接(覆盖内容)的孩子。现在,叠加内容是可以缓存的,因为它是包装div的子节点,它将导致:hover在整个包装div上保持活动状态。

答案 1 :(得分:1)

我建议使用JS样式交换而不是CSS指针事件来解决这个问题。当鼠标悬停在底角时,您需要触发对css的一次更改,当您将鼠标移出容器时,需要单独执行一次更改。我不相信CSS会给你那种条件控制。

答案 2 :(得分:0)

这是使用动画而不是过渡的半个解决方案。当你将鼠标悬停在amg-corner-button_wrap上时,这种方法有效,但是当你移开它时则不适用。我对动画有点新意,所以希望有更多知识的人可以帮助你下半场。

如果你将鼠标悬停在amg-corner-button_wrap上并悬停在过渡中间,那么这里还有一个奇怪的视觉效果。这样做的原因是我为叠加内容添加了背景颜色,因此当它淡入并且你将鼠标移开amg-corner-button_wrap时,滑动在淡入淡出完成之前开始反转。

无论如何,希望这个50%的解决方案可以帮助您或其他人将其提升至100%!不得不参加会议,祝你好运: - )

@keyframes example {
  0% {
    visibility: hidden;
    opacity: 0;
  }
  1% {
    visibility: visible;
    opacity: 0;
  }
  100% {
    visibility: visible;
    opacity: 1;
  }
}

.panel-default1 {
  padding-top: 10px;
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.10);
  height: 200px;
  width: 200px;
  overflow: hidden;
  margin: 0 auto;
  position: relative;
}

.amg-corner-button_wrap {
  display: block;
  background-color: #e8c63d;
  position: absolute;
  transform: rotate(45deg);
  right: -120px;
  bottom: -120px;
  width: 200px;
  height: 200px;
  -moz-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  -webkit-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out;
}

.overlay-content {
  visibility: hidden;
  opacity: 0;
  background-color: #e8c63d;
  bottom: 0;
  color: #333;
  left: 0;
  padding: 30px;
  position: absolute;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  right: 0;
  top: 0;
}

.overlay-content h2 {
  border-bottom: 1px solid #333;
  padding: 0 0 12px;
}

.overlay-content~.amg-corner-button_wrap,
.amg-corner-button_wrap:hover {
  transform: rotate(45deg) scale(4);
}

.amg-corner-button_wrap:hover~.overlay-content,
.overlay-content:hover {
  animation-name: example;
  animation-duration: 0.3s;
  animation-timing-function: linear;
  animation-delay: 0.3s;
  animation-fill-mode: both;
}
<div class="panel panel-default1">
  <div class="panel-body">
    <a href="#" onclick="alert('outer')">Link</a>

    <div class='amg-corner-button_wrap'></div>

    <div class="overlay-content">
      <h2>Image Ink Logo</h2>
      <a href="#" onclick="alert('inner')">Link</a>
    </div>

  </div>
  <!-- panel body -->

</div>
<!-- panel default -->

答案 3 :(得分:0)

这里只是改变css和html的工作小提琴:https://jsfiddle.net/y2auh7gn/4/

它将链接与select id1, id2, (select count(*) from mytable as t2 where t1.id1 = t2.id1) "count" from mytable as t1 分开,并将其放置在overlay-content所在的位置。我们需要将链接移出position: absolute,这样当我们将鼠标悬停在其上时,叠加层就不会消失。

有一个副作用,链接弹出一个角落。