简体   繁体   English

如何知道一个元素是否在屏幕上完成显示(完成渲染) - Javascript

[英]How to know if an element has finished displaying on the screen (finished rendering) - Javascript

Let's see if someone comes up with something.让我们看看是否有人提出了什么。 I have the following problem:我有以下问题:

I need to know, with javascript or jquery, when an element has finished displaying on the screen.我需要知道,当一个元素在屏幕上完成显示时,使用 javascript 或 jquery。

It is a table that is displayed on the screen as a modal popup window.它是一个在屏幕上显示为模态弹出窗口 window 的表格。 It has a main container div with the size of the entire viwport, with a z-index of 10000 and display flex so that the div that acts as a popup window is centered.它有一个主容器 div,其大小与整个 viwport 相同,z-index 为 10000 并显示 flex,因此充当弹出窗口 window 的 div 居中。 What I need to know is the clientWidth and offsetWidth properties of the body of the table to determine the width of the scroll bar which is equal to offsetWidth - clientWidth, and apply this width to the right margin of another div.我需要知道的是表格主体的clientWidth和offsetWidth属性,以确定滚动条的宽度等于offsetWidth - clientWidth,并将此宽度应用于另一个div的右边距。

When the table is finished filling in a javascript function, the d-flex class is added to the main container so that the popup modal window is displayed. When the table is finished filling in a javascript function, the d-flex class is added to the main container so that the popup modal window is displayed.

The problem is that until the popup is not physically seen on the screen it gives me that both properties are the same, that is, there is no scroll bar visible.问题是,直到在屏幕上没有实际看到弹出窗口,它给我的两个属性是相同的,也就是说,没有可见的滚动条。 Only when popup appears on the screen is that they are different because there is a scroll bar.只有当屏幕上出现弹出窗口时,它们才不同,因为有滚动条。 The scroll bar only appears when the popup has been physically displayed on the screen.仅当弹出窗口已物理显示在屏幕上时,才会出现滚动条。

If I ask for any visibility properties they tell me that everything is visible but it hasn't really been shown on the screen yet.如果我询问任何可见性属性,他们会告诉我一切都是可见的,但还没有真正显示在屏幕上。

I've even tried with a jQuery extension of the show function, but it doesn't give me the results I need either.我什至尝试过使用节目 function 的 jQuery 扩展,但它也没有给我需要的结果。

Thank you very much for your collaboration.非常感谢您的合作。

Greetings问候

You could do a work around IF you never desire the two property values to be the same.如果您从不希望两个属性值相同,则可以解决此问题。 You could implement a setInterval to keep checking the property values:您可以实现 setInterval 以继续检查属性值:

let x = setInterval(function(){
    if (propertyValue1 !== propertyValue2){
      clearInterval(x);
      //do or trigger any code that you need to here
    }
},100)

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

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