Get offsetParent as null

problem description

when the image is loaded lazily and the encapsulation method obtains the offset-related value of the element, offsetParent always explains for null,mdn that if the dispaly of the element is none or the offsetPsrent obtained when the element is body, it will be null, but does not belong to both cases. What is the problem?

Source address

https://smileyby.github.io/pi.

Apr.22,2021

less.js hides body before the style file is compiled to prevent the page from flickering due to style updates.

when your script acquires offsetParent, the style in the page has not yet been compiled, and the display setting of body will be set to none. by less So you can't get offsetParent.

.

clipboard.png

Menu