首页 > 解决方案 > 悬停时将一个块移到另一个块上

问题描述

当我在红色 div 上移动鼠标时,我希望灰色 div 稍微靠上一点。但是当它移动并且鼠标碰巧在红色 div 上时,它开始滞后并在上下移动之间犹豫。我应该为这个动画做些什么来避免这种犹豫和移动灰色物体平滑?

.dm-intro-news {
width: 200px;
height: 200px;
background: red;
transition: 0.5s;
}
.dm-intro-news {
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
}
.wr {display: inline-block;transition:2s}
.dm-short-news{
  display:inline-block;
  overflow: hidden;
  width: 390px;
  height: 40px;
  background: red;
  position: relative;

}
.dm-short-news:hover~.dm-intro-news{
  margin-top:-50px;
  position: absolute;
}
<div class="wr">
  		<div class="dm-short-news"></div>
  		<div class="dm-intro-news"></div>
</div>

标签: htmlcss

解决方案


.dm-intro-news这是因为悬停事件在顶部时将被取消。

穿上:pointer-events: none;_.dm-intro-news

.dm-intro-news {
width: 200px;
height: 200px;
background: red;
transition: 0.5s;
}
.dm-intro-news {
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
}
.wr {display: inline-block;transition:2s; position: relative;}
.dm-short-news{
  display:inline-block;
  overflow: hidden;
  width: 390px;
  height: 40px;
  background: red;

}
.dm-short-news:hover::before {
  content: '';
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
    }
.dm-short-news:hover~.dm-intro-news {
  margin-top:-50px;
  pointer-events: none;
  position: relative;
  z-index: 1;
}
<div class="wr">
  		<div class="dm-short-news"></div>
  		<div class="dm-intro-news"></div>
</div>


推荐阅读