最近我一直在研究 Shower HTML5+CSS3 presentation template进行即将进行的演示。花洒用CSS :target
pseudo-class这使得在幻灯片概览中轻松识别当前幻灯片。
我理解 :target
如何通过 URL 中的散列工作,但是我无法让它从所有元素中清除 :target
CSS。
所以我的问题是:假设在元素被 :target
编辑后,我们如何清除所有 :target
并使用 JavaScript 将其恢复为标准?使用 History API 似乎不起作用。
最佳答案
我之前尝试过以下两个语句,但没有用(至少在 Firefox 上):
history.pushState({}, 'null', window.location.pathname);
window.location.href.substr(0, window.location.href.indexOf('#'));
诀窍是改用它:
window.location.hash = '';
只有当我们尝试通过 JavaScript 清除 :target
选择时,问题才会存在。具有不存在或空哈希值的 anchor 标签有效:http://jsfiddle.net/SMbsb/3/
关于javascript - 清除 :target CSS psuedo class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12906509/