【发布时间】:2023-03-03 02:43:02
【问题描述】:
我正在使用几乎纯 css,(仅在 css 中执行此操作不是要求)背景图像和相邻选择器用于呈现独特的人类可读的页面当用户将鼠标悬停在水平堆叠的图像上(在页面的右侧,其中每个图像都使用顺序后缀的类名进行唯一分类,即, .hover1, .hover2, 到 .hover7)。
如果您加载页面(在下面的 jsfiddle 链接中)并运行代码,则页面可以正常工作。但是,我想启用“粘滞”悬停状态,当用户将光标移出图像时,图像和随附文本的状态保持悬停状态,直到:鼠标悬停另一个图像或一段时间过去了。假设是 10 秒。
例如;这是图像的两行 HTML:
<div class="hover1"></div>
<div class="hover1text hovertext">
<h3>Best-in-Class BBQ</h3>
<p>tons of text</p>
<p>Lots more awesome text</p>
</div>
<div class="hover2"></div>
<div class="hover2text hovertext">
<h3>Penetration and Vulnerability Tenderloin</h3>
<p>More awesome text</p>
<p>What you wanted</p>
</div>
etc for the balance of the 7 items
我的 CSS 的一部分:
.context-services .region-inner .field-name-body .float-right .hover1 {
background-image: url(https://dl.dropboxusercontent.com/u/67315586/buttons/1_off.png);
transition: 0s background;
}
.context-services .region-inner .field-name-body .float-right .hover1:hover {
background-image: url(https://dl.dropboxusercontent.com/u/67315586/buttons/1_hover.png);
transition: 0s background;
}
.context-services .region-inner .field-name-body .float-right .hover1 + .hover1text {
opacity: 0;
transition: 0s all;
}
.context-services .region-inner .field-name-body .float-right .hover1:hover + .hover1text {
opacity: 1;
transition: 0s all;
}
我的 jsfiddle.net 是 here。
任何见解都值得赞赏;谢谢!
【问题讨论】:
-
你介意使用javascript吗?纯 css 在这里有点难......
-
Herrington Darkholme 我同意。我只是觉得这很酷,我只能用 css 做到这一点。我更喜欢基于 JS 的解决方案。
-
我认为在 jquery 中使用 addClass 是一个更好的解决方案。我正在尝试。