question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gallery not working when container div is hidden (display:none)

See original GitHub issue

I want the swiper gallery to show after clicking on a “Show the gallery” link. But it looks like Swiper is not working properly if initialized inside an hidden div.

Here is my page:

<div>
<a href=“javascript:;” onclick=“toggle_visibility('gallery');”><img src=“img.jpg” alt=“Click to open the gallery”></a>
</div>

<div id=“gallery” style:“display:none”>
<!— Swiper —>
<div id=“slide-event” class=“swiper-container swiper-container-event”>
<div class=“swiper-wrapper”>
…
</div>
<!— Add Arrows —>
<div id=“show-hide” class=“swiper-button-next”></div>
<div id=“show-hide” class=“swiper-button-prev”></div>
</div>
<!— End Swiper —>
</div>

<script src="js/swiper.jquery.js"></script>

Maybe there is a javascript trick? I read about a setTimeout function that could fix this issue. Any suggestion?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

203reactions
wwwwwwoorkscommented, Jan 13, 2017

It is far easier than this. Just add:

observer: true,
observeParents: true,

To the swiper initialization.

4reactions
MaxInMooncommented, Jun 5, 2017

@wwwwwwoorks, thanks it works 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Css display none not working on div and its contents
Having a little trouble with css display:none. The problem is I want to hide a div that contains a repeater on large screens...
Read more >
How To Find Out if an Element is Hidden - W3Schools
Note: When an element is hidden with display:none (like in the example above), the element will not take up any space. To find...
Read more >
display - CSS: Cascading Style Sheets - MDN Web Docs
The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, ......
Read more >
Hide or show elements in HTML using display property
The style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery.
Read more >
Display property - Bootstrap
To hide elements simply use the .d-none class or one of the .d-{sm,md,lg,xl}-none classes for any responsive screen variation. To show an element...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found