【问题标题】:`:target` styles acting strange in IE11`:target` 样式在 IE11 中表现得很奇怪
【发布时间】:2015-09-24 03:07:43
【问题描述】:

我为div:target 写了一些特殊的样式。当我点击<a href="#target"> 时,Chrome、Firefox 和 IE9+IE11 运行良好。现在我单击“返回”按钮(或“javascript: history.go(-1)”),我的 URL 栏立即返回,但 IE 拖着脚回到默认样式,有时需要 3-5 秒,有时它不会更新 ,直到我按下 F12 并尝试检查有问题的元素(然后它会立即更新)。什么给了?

更新:这似乎只发生在 IE11 中。使用(本机安装)IE9 的每个人都没有问题。即使用 IE11 模拟 IE9 也会有问题。

http://jsfiddle.net/r1rqp1sc/2/:

$('#hello').click(function(){
    history.go(-1);
});
div {
    width: 100px; height: 100px;
    background: gray; color: white;
    cursor: pointer;
}
div:target { background: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a href="#hello">Hello</a>
<div id="hello">Click here to go history:back()</div>

【问题讨论】:

    标签: css internet-explorer browser-history pseudo-class


    【解决方案1】:

    所以这并不能回答问题,但它似乎与 IE11 在遍历历史后没有有效地重绘有关。显然,仅在该元素上添加或删除一个类将强制重绘该元素。

    $('#hello').click(function(){
        history.go(-1);
        $(this).addClass('z').removeClass('z');
    });
    

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2014-12-12
      • 2012-11-11
      相关资源
      最近更新 更多