Skip to content

Measuring element width in a layout that uses flexbox layout #123

@mindplay-dk

Description

@mindplay-dk

Working on a site that uses flexbox CSS layout, I ran into an issue where only the lowest-resolution image would get loaded, even after resizing.

I narrowed it down to image.parentNode.clientWidth always returning zero in the determineAppropriateResolution function.

Adding a second fallback to offsetWidth seems to fix the issue:

Imager.prototype.determineAppropriateResolution = function (image) {
  return Imager.getClosestValue(image.getAttribute('data-width') || image.parentNode.clientWidth || image.parentNode.offsetWidth, this.availableWidths);
};

My problem isn't completely fixed- it still doesn't initially load the correct size image, but this seems to be an important step on the way.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions