Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The description box doesn't expand to the full width when the image is not preloaded #291

Open
inacho opened this issue Sep 26, 2021 · 3 comments
Labels

Comments

@inacho
Copy link

inacho commented Sep 26, 2021

Describe the bug
The description box doesn't expand to the full width when changing the slide and the image is not preloaded yet.
This issue happens a lot when you flick through photos in a gallery with images that have good quality (as they take longer time to completely load).

Are you able to reproduce the bug in the demo site
Yes

To Reproduce
Steps to reproduce the behavior:

In order to reproduce the bug easier, use a browser with an inspector that allows to throttle the network speed. For instance Firefox.

  1. Open a gallery with Firefox
  2. Open the inspector and go to the "network" tab
  3. Activate network throttling (for example "Regular 2G")
  4. Open one slide, then change to other slides quickly

Expected behavior
The description should expand to the same width of the image instead of being tiny

Screenshots

Screen Shot 2021-09-26 at 12 31 21

Video

bug.mov
@gingerchew
Copy link
Collaborator

Hey there @inacho,

Thanks for submitting this bug report!

I can confirm I'm seeing this issue too on Firefox 92.0.1 on my Macbook when I set the network throttle to 2g.

Just as a "Let's see how bad I can make it", I was able to get this to occur:
image

Where the first and last slides both are given the class of .current. I don't have the time right now to do any proper testing, but this at least confirms that the bug can occur.

@inacho in your testing/coding, did you run into any solutions or workarounds? Were you able to get it to occur on actual devices or only in an emulator like Firefox Dev tools?

@gingerchew gingerchew added the bug label Oct 25, 2021
@inacho
Copy link
Author

inacho commented Nov 13, 2021

Hey,

I'm using the following workaround:

Basically moving the div.gslide-description inside .gslide-media instead of having it as a sibling, so when .gslide-media expands, the description will expand as well.

Javascript:

let customSlideHTML = `<div class="gslide">
    <div class="gslide-inner-content">
        <div class="ginner-container">
            <div class="gslide-media">
              <div class="gslide-description">
                  <div class="gdesc-inner">
                      <h4 class="gslide-title"></h4>
                      <div class="gslide-desc"></div>
                  </div>
              </div>
            </div>
        </div>
    </div>
</div>`;

let glightbox = GLightbox({
    slideHTML: customSlideHTML,
});

CSS:

.glightbox-clean .gslide-description {
    max-width: 100% !important;
}

.glightbox-clean .gdesc-inner {
    -webkit-user-select: auto;
    -moz-user-select: auto;
    -ms-user-select: auto;
    user-select: auto;
}

.glightbox-clean .gdesc-inner a {
    display: inline-block;
}

Until I applied the workaround the issue was happening to me with regular jpegs of 1200x800 pixels (2400x1600 size for retina devices) hosted in Amazon S3 with Cloudfront as CDN (home internet speed is 1Gbps).
This is the website where the issue was happening: https://nacho.tokyo/en

The images used in the example site are only like 25KB, and there are only 3. That's way is more difficult to reproduce the issue there unless you throttle the network.

@ncla
Copy link

ncla commented Dec 21, 2021

Thanks inacho for the idea. Unfortunately your workaround comes with a regression on mobile viewports where description overlays the slide (upon changing slides or interacting with the slide). Transform gets applied to gslide-media and as such the parent stacking context changes to that element causing description to be positioned incorrectly.

I looked a bit at the source code and one way to fix this decently would be a proper detection of when content has loaded in. The calculation is coming from resize method that calculates description max width, which is done with a setTimeout delay of 100. Not reliable.

setTimeout(() => {
this.resize(slide);
}, 100);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants