html - 悬停时将一个块移到另一个块上
问题描述
当我在红色 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>
解决方案
.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>
推荐阅读
- javascript - 如果我们在 render 方法中调用异步函数会发生什么?
- java - 如何修改方法利用枚举成员
- c++ - 多行宏导致“预期声明”错误
- javascript - 如何在没有 cocoapod 的情况下在 0.60.0 版中创建反应原生应用程序?
- jquery - Ajax formdata文件上传进度百分比
- javascript - 使用 window.open 后更改 HTML 属性
- java - 在 onCreate 中初始化变量,但在 onResume() 中更新它们
- python-2.7 - Python smtplib 电子邮件不会发送到外部地址
- excel - 连续计算多个日期范围内的唯一日期
- javascript - Child_Processes 从 javascript 节点 js 调用函数到 python 中断导入