简体   繁体   English

如何说服Firefox重绘CSS伪元素?

[英]How can I convince Firefox to redraw CSS Pseudo-elements?

I'm having issues getting Firefox to update a webpage when its class is changed dynamically. 动态更改类时,让Firefox更新网页时出现问题。

I'm using an HTML table element. 我正在使用HTML table元素。 When the user clicks a cell in the table header, my script toggles the class back and forth between sorted_asc and sorted_des . 当用户单击表标题中的单元格时,我的脚本在sorted_ascsorted_des之间来回切换类。 I have pseudo element which adds an arrow glyph (pointing up or down) depending on which class the cell currently is. 我有伪元素,它根据当前单元格的类别添加一个箭头标志符号(向上或向下)。

.thead .tr .sorted_asc .cell:after {
    content: ' \25B2';
}

The problem is, that when you click the cell header a second time, the page doesn't update the arrow... until the user mouses away from the element. 问题是,当您第二次单击单元格标题时,页面不会更新箭头...直到用户将鼠标从元素上移开。 I think it's a bug as it works fine in Safari, and as I don't see any :hover tags in my CSS or other entries that might interfere. 我认为这是一个错误,因为它可以在Safari中正常工作,并且我在CSS或其他可能不会造成干扰的条目中看不到任何:hover标记。

Anyone seen this before, or know how to work around the issue? 任何人以前都看过此书,或者知道如何解决此问题?

This is 2014 and none of the proposed solutions on this page seem to work. 这是2014年,本页上的拟议解决方案似乎都无效。 I found another way : detach the element from the DOM and append it back where it was. 我发现了另一种方法:将元素与DOM分离,然后将其附加回原处。

It's kind of cheesy, but since you're using javascript anyway, try this after you changed the className: 有点俗气,但是由于无论如何您都在使用javascript,因此请在更改className之后尝试执行以下操作:

document.body.style.display = 'none';
document.body.style.display = 'block';

This will re-render the layout and often solves these kind of bugs. 这将重新渲染布局,并且通常可以解决此类错误。 Not always, though. 并非总是如此。

Would you be able to use different CSS to accomplish the same thing without relying on the :after pseudo-selector? 您是否可以使用不同的CSS来完成相同的事情而无需依赖:after伪选择器? You might be able to simple define a background-image which you align as needed (I assume you would want the arrow on the right hand side). 您也许可以简单地定义一个背景图像,然后根据需要进行对齐(我想您需要右侧的箭头)。

For example: 例如:

.thead .tr .sorted_asc .sorted_asc {
  background: url(images/down_arrow.png) no-repeat right;
}

.thead .tr .sorted_asc .sorted_des {
  background: url(images/up_arrow.png) no-repeat right;
}

I only suggest this since I assume there isn't a specific reason why you need to use the :after pseudo-class. 我只建议这样做,因为我认为没有特定的原因需要使用:after伪类。 If you do need to use it, please update. 如果您确实需要使用它,请进行更新。

The bug can still be triggered in Firefox 58. Thankfully the opacity trick also still works. 该错误仍可以在Firefox 58中触发。幸运的是,这种不透明技巧仍然有效。 Just make sure to time it correctly. 只要确保正确的时间。 You might need to set a timeout between opacity changes. 您可能需要在不透明度更改之间设置超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM