0
我将如何保持这些状态(:hover,:focus,:active等)处于活动状态,直到发布?JavaScript - 保持伪类(:hover,:active,:focus)处于活动状态,直到发布
看看这个例子:
<style> div:hover, div:focus, div:active { background: red; } </style>
<div tabindex="-1">I would be red, if hovered, focused or being active. Until the button 'toggle off' is pressed.</div>
<button onclick="toggleItem('on', 'hover');">Toggle on</button>
<button onclick="toggleItem('off', 'hover');">Toggle off</button>
function toggleItem(action, style)
{
if (action == "on")
{
// style activation
}
else if (action == "off")
{
// disable activated style
}
}
我在想设定的时间间隔,这将触发此状态下每x秒。但似乎并不是“良好的做法”......任何建议?
基本上就像开发工具:
这是不可能的。最好的办法是使用对应于相应状态的类名('div:hover,div.hover,...'),并切换这些。 – CBroe
@CBroe我已经用图像更新了我的问题。他们如何支持这个功能? –
开发工具/浏览器扩展可访问较低级别的API等,您无法在常规网站范围内访问该API。 – CBroe