html - 有没有办法让 ":hover" 停留?
问题描述
有没有办法让:hover
评论在你离开鼠标之后仍然保留?
由于它而不起作用的示例:
#SS {
width: 300px;
height: 300px;
background-image: url(https://media1.tenor.com/images/a8479ab2587f60773c0032ada0c85d3b/tenor.gif?itemid=5751040);
background-size: cover;
margin: auto;
}
#SS:hover {
transform: translate(500px);
}
#SS p {
text-align: center;
font-size: 140%;
font-weight: bold;
color: red;
text-shadow: 0 0 5px black;
padding-top: 265px;
}
<div id="SS">
<p>You will never catch me!!!</p>
</div>
解决方案
这是一种使用 JS 的方法,我建议使用这个:
var ss = document.getElementById('SS');
ss.addEventListener('mouseover', function() {
//ss.classList.add('SS-hover');
ss.classList.toggle('SS-hover');
})
#SS {
width: 300px;
height: 300px;
background-image: url(https://media1.tenor.com/images/a8479ab2587f60773c0032ada0c85d3b/tenor.gif?itemid=5751040);
background-size: cover;
margin: auto;
}
.SS-hover {
transform: translate(500px);
}
#SS p {
text-align: center;
font-size: 140%;
font-weight: bold;
color: red;
text-shadow: 0 0 5px black;
padding-top: 265px;
}
<div id="SS">
<p>You will never catch me!!!</p>
</div>
推荐阅读
- java - 如何在 JAVA 16.0 中发送 HTTP 请求
- php - wkhtmltopdf / phpwrapper 做内部 URL
- r - 转换系列并根据原始列命名
- java - 在java中从键盘输入价格
- python - Postman Django CSRF 请求 get_auth_token 路由时出错
- node.js - 对猫鼬中的值求和
- python - python中的数据矩阵GS1
- django - 在 django 中单击按钮获取输入值
- windows-10 - Pgadmin4 不会显示在 Windows 10 系统托盘上
- linux - 有没有办法通过 SSH 隧道转发串行控制台访问?