javascript - 为什么在 div 上添加 mouseover 效果即使在 mouseout 之后效果仍然存在?
问题描述
我的意思是如何在鼠标退出时保留实际的上一课?
function highlight( x, y) {
var sel=document.getElementById(y);
sel.style.borderBottom= "2px solid "+x;
sel.style.opacity="1";
sel.style.transition="all ease-in .1s"
}
即使鼠标移出,过渡仍然存在,我需要鼠标移出的旧 CSS 类。
解决方案
您实际上是在为您的元素设置样式“永远”:sel.style.opacity = 1
. 尝试向您的元素添加一些 CSS 悬停逻辑,例如:
CSS:
.box {
background-color: red;
}
.box:hover {
background-color: green;
cursor: pointer;
-webkit-transition: background-color 2s ease-out;
-moz-transition: background-color 2s ease-out;
-o-transition: background-color 2s ease-out;
transition: background-color 2s ease-out;
}
HTML:
<div class='box'>Your element</div>
推荐阅读
- python - 如何通过scrapy绕过确认年龄模型
- java - 在数据流服务器中运行时出现spring cloud task taskLifecycleListener错误
- java - 自动化 jproflier 分析和保存 sanpshots
- oracle - 如何在 Oracle APEX 中为交互式报表的所有列设置相同的固定宽度?
- c# - 在 Asp .Net Webform 中使用 Excel 2016 扩展名 xlsx 导出
- php - 如何从 Google_Service_PeopleService 获取数据?
- php - 如何在 php 中使用 FPDF 在多列上换行?
- google-cloud-firestore - Firestore中部分数据上传的标准做法错误处理?
- mysql - MySQL 5.6 CAST String to Int 返回错误 1064
- ruby-on-rails - 无法在画布 lms 中投递邮件?我缺少什么配置设置?