Load not work when parent element has display: none;
See original GitHub issueWhen I have a <LazyLoad>
inside an element with display: none
and I change this display to block, the content not load. This content only will load after a scroll interaction.
The code is like that:
export default function App() {
const [tab, setTab] = useState(1);
return (
<div className="App">
<ul className="tabs">
<li>
<button onClick={() => setTab(1)}>tab 1</button>
</li>
<li>
<button onClick={() => setTab(2)}>tab 2</button>
</li>
</ul>
<div className="content">
<div style={{ display: tab === 1 ? "block" : "none" }}>
<p>Content of tab 1</p>
<LazyLoad>
<img src="https://via.placeholder.com/150?text=Content 1" alt="1" />
</LazyLoad>
</div>
<div style={{ display: tab === 2 ? "block" : "none" }}>
<p>Content of tab 2</p>
<LazyLoad>
<img src="https://via.placeholder.com/150?text=Content 1" alt="2" />
</LazyLoad>
</div>
</div>
</div>
);
}
The problem is that:
And the complete code is here:
https://codesandbox.io/s/determined-hoover-z6cff?file=/src/App.js:104-960
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Does a parent element with "display: none" cause child imgs ...
Based on related questions here on SO, the general solution seems to be to use $(window).load(func); to run the grayscale generation code.
Read more >HTML DOM Style display Property - W3Schools
Property Values ; none, Element will not be displayed ; run-in, Element is rendered as block-level or inline element. Depends on context ;...
Read more >display - CSS: Cascading Style Sheets - MDN Web Docs
Using a display value of none on an element will remove it from the accessibility tree. This will cause the element and all...
Read more >What is the difference between visibility:hidden and display ...
Both the visibility & display property is quite useful in CSS. ... none: It will not display any element. inline: It is the...
Read more >Comparing Various Ways to Hide Things in CSS
If an image tag (or parent element) has a display property set to none either through inline CSS or by selector, the image...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@geraldstrobl I created my own implementation using IntersectionObserver. But before it, I needed to change the location of the
<LazyLoad />
.Hi, is it fixed ?