首页 > 解决方案 > chrome 和 IE 中的 ScrollHeight 值不同

问题描述

如果元素溢出,我想将一个类应用于 div 。为此,我将 ScrollHeight 与 ClientHeight 进行比较。它在 chrome 上运行良好,但在 IE 中不行。下面是代码片段:

componentDidMount() {
   this.assign_overflow();
}

assign_overflow = () => {
    const element = this.title_ref.current;
    element.classList.toggle('overflowing', element.scrollHeight > 
    element.clientHeight);
};

<div>
    <h5 ref={this.title_ref}>header</h5>
</div>

.overflowing::after {
    content: "...";
    position: absolute;
    bottom: -2px;
    background-color: yellow;
}

在 IE 中,我看到应用于元素的类“溢出”,即使它不应该是。此外,在 chrome 中,我将 scrollheight 值设为 20,在 IE 中为 22。有人可以帮我解决这个问题。谢谢。

标签: javascriptreactjs

解决方案


推荐阅读