简体   繁体   English

当innerHTML更改时,Chrome不会刷新div大小

[英]Chrome not refresh div size when innerHTML changed

The question is,问题是,

"How can you have CSS after style display correctly in Chrome when a div gets resized?" “当 div 调整大小时,如何在 Chrome 中正确显示样式后使用 CSS?”

and,和,

"Has anyone had any issues with Chrome recently with elements not displaying correctly after change an elments innerHTML from JavaScript?" “最近有没有人在 Chrome 中遇到任何问题,在从 JavaScript 更改元素 innerHTML 后元素无法正确显示?”

or,或者,

"Does anyone know of any bugs logged in Chrome for CSS display issues on resize (with link)?" “有没有人知道 Chrome 中记录的任何错误,用于调整大小(带链接)时的 CSS 显示问题?”

and,和,

"Does anyone know of a good workaround to this issue?" “有人知道解决这个问题的好方法吗?”

I have a chat SDK that does bubble chat.我有一个可以进行气泡聊天的聊天 SDK。

Recently I have noticed that the bubbles little tail is not displayed correctly when the chat bubble resizes.最近我注意到聊天气泡调整大小时,气泡小尾巴没有正确显示。 It only occurs on Chrome, Firefix, IE, etc. are ok它只发生在 Chrome、Firefix、IE 等上都可以

Seems like a Chrome bug, and I'm sure it used to work ... :( but not sure how long the bug is going to stay this way...似乎是 Chrome 的错误,我确定它曾经可以工作...... :( 但不确定这个错误会保持多久......

What bubble looks like when the text is updated,文本更新时气泡的样子,

在此处输入图片说明

What it should look like,它应该是什么样子,

在此处输入图片说明

I have a hack to fix it, by changing the parent div padding to something different, then setting a timeout to change it back (only works with a timeout)我有一个 hack 来修复它,通过将父 div 填充更改为不同的东西,然后设置超时以将其更改回来(仅适用于超时)

Anyone know a better way to fix this, or when this broke in Chrome and if they will ever fix it?任何人都知道解决这个问题的更好方法,或者当它在 Chrome 中崩溃时,他们是否会修复它?

// Fix Chrome bug,
if (SDK.isChrome()) {
    var padding = document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding;
    document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding = "7px";
    setTimeout(function() {
        document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding = padding;
    }, 10);
}

The css for the tail is,尾巴的 css 是,

bubble:before { content:''; position:absolute; bottom:0px; left:40px; border-width:20px 0 0 20px; border-style:solid; border-color:black transparent; display:block; width:0;}
bubble:after { content:''; position:absolute; bottom:3px; left:42px; border-width:18px 0 0 16px; border-style:solid; border-color:white transparent; display:block; width:0;}
// Fix Chrome bug,
if (SDK.isChrome()) {
    var padding = document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding;
    document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding = "7px";
    setTimeout(function() {
        document.getElementById(this.prefix + 'response').parentNode.parentNode.style.padding = padding;
    }, 10);
}

is the only solution.是唯一的解决办法。

Can you try something like this by setting the parent height with bubble's scroll height as below,您可以通过设置带有气泡滚动高度的父高度来尝试这样的事情,如下所示,

// Fix Chrome bug,
function fixChromeBug(){
    if (SDK.isChrome()) {
        // this is your bubble element and change accordingly
        var bubble = document.getElementById('bubble');
        // Below should be an actual parent
        var parent = bubble.parentNode;
        // or this if required
        //var parent = bubble.parentNode.parentNode;
        parent.style.height = bubble.scrollHeight + parent.style.padding + 'px';
    }

}
    setTimeout(function() {
      fixChromeBug();
      document.getElementById('imageIfAny').onload = fixChromeBug;
   }, 1);

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

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