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