清除:目标CSS psuedo类 [英] Clearing off :target CSS psuedo class
问题描述
最近,我一直在使用 Shower HTML5 + CSS3演示模板来制作即将发布的演示文稿。 Shower使用 CSS :target
伪类<
Lately I've been working on Shower HTML5+CSS3 presentation template to make a upcoming presentation. Shower uses the CSS :target
pseudo-class which makes it easy to identify the current slide in the overview of the slides.
我知道:target
通过URL中的哈希值工作,但是我无法从所有元素中清除:target
CSS。
I understand how :target
works through the hash in the URL, but however I cannot get it to clear the :target
CSS from all elements at all.
所以我的问题是:假设一个元素:target
ed后,我们如何清除:target
并使用JavaScript将其还原为规范?使用History API似乎不工作。
So my question is: given that after an element has been :target
ed, how can we clear all the :target
and revert it to the norm using JavaScript? The use of History API doesn't seem to work.
推荐答案
我以前尝试过以下两个语句,但没有工作(至少在Firefox上):
I previously tried the following two statements and it didn't work (at least on Firefox):
history.pushState({}, 'null', window.location.pathname);
window.location.href.substr(0, window.location.href.indexOf('#'));
诀窍是改用:
window.location.hash = '';
问题只有在我们试图清除:target
通过JavaScript选择。使用不存在或为空的哈希值的锚定标记的工作原理: http://jsfiddle.net/SMbsb/3/
The problem only exists if we're trying to clear the :target
selection through JavaScript. Anchor tags with non-existing or empty hashes works: http://jsfiddle.net/SMbsb/3/
这篇关于清除:目标CSS psuedo类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!