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.

Full Width Carousel Slider Height Not Initialized Correctly

See original GitHub issue

Expected Behavior

A .carousel-slider Carousel with fullWidth: true option should initialize it’s height in proportion to the current window width also if the first image hasn’t loaded completely at the time of carousel initialization.

Current Behavior

A .carousel-slider Carousel with fullWidth: true option doesn’t initialize it’s height in proportion to the current window width if the first image hasn’t loaded completely at the time of carousel initialization. Instead it initializes itself to the default height (400px) which may leave a gap below the carousel if the images are not that high.

Possible Solution

The bug seems to be in materialize/js/carousel.js:

    _setCarouselHeight(imageOnly) {
      let firstSlide = this.$el.find('.carousel-item.active').length
        ? this.$el.find('.carousel-item.active').first()
        : this.$el.find('.carousel-item').first();
      let firstImage = firstSlide.find('img').first();
      if (firstImage.length) {
        if (firstImage[0].complete) {
          //...
        } else {
          // Get height when image is loaded normally
// next line changed: single event function parameter "ev"
          firstImage.one('load', function (ev) {
// next line changed: get offsetHeight from "ev.target"
            _this65.$el.css('height', ev.target.offsetHeight + 'px');
          });
        }
      } else if (!imageOnly) {
        let slideHeight = firstSlide.height();
        this.$el.css('height', slideHeight + 'px');
      }
    }

Original code seems to assume getting an element reference as parameter to the ‘load’ event handler because calls it el and tries to get offsetHeight from this parameter which of course fails.

Steps to Reproduce

Seems to occur only with many and large images in the carousel.

Your Environment

Seems not to be relevant here.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
harri00413commented, Mar 30, 2020

Looks like Materialize is no longer maintained.

1reaction
josh432commented, Jan 21, 2020

Hello, I’m encountering this carousel bug with large images (about 13 images). The carousel sometimes shrinks to 400px on page load. I couldn’t figure out why it was doing this for days but I finally thankfully found this issue. I’m using the materialize cdn. Will this issue be resolved/closed? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

carousel image not being full width even with min-width:100%
I tried adding width to img simply it does work, Is this expected behaviour? .carousel-inner img { width: 100%; height: 200px !important; }...
Read more >
Topic: revolution slider not stretching full width - Themeco
I had made the sliders on a grid size of 1240px width, but since it's set to expand full-width responsively, shouldn't it do...
Read more >
Is Your WordPress Slider Not Working? Here's How to Fix It!
1. Your Slider's Images Don't Appear On Your Site ... A clear issue is when your slider loads, but doesn't display images. In...
Read more >
Not showing proper image width | WordPress.org
In the slide settings page, each slider has the full size img added so the ... to the correct height because otherwise, it...
Read more >
Carousel · Bootstrap v5.2
Carousels don't automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content.
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