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

Improve image sizes in the multicolumn section #2349

Merged
merged 6 commits into from
Mar 10, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions sections/multicolumn.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,29 @@
style="padding-bottom: {{ 1 | divided_by: highest_ratio | times: 100 }}%;"
{% endif %}
>
{%- capture sizes -%}
(min-width: 990px) {% if section.blocks.size <= 2 %}710px{% else %}550px{% endif %}, (min-width:
750px) {% if section.blocks.size == 1 %}710px{% else %}550px{% endif %}, calc(100vw - 30px)
{%- endcapture -%}
{%- liquid
assign number_of_columns = section.settings.columns_desktop
assign number_of_columns_mobile = section.settings.columns_mobile
assign max_image_width = settings.page_width | times: 2
if section.settings.image_width == 'half'
assign image_width = 0.5
elsif section.settings.image_width == 'third'
assign image_width = 0.33
else
assign image_width = 1
endif
-%}
{% capture sizes %}
(min-width: 990px) {{ settings.page_width | times: image_width | divided_by: number_of_columns | round: 0 }}px,
calc(100vw * {{ image_width }} / {{ number_of_columns_mobile }})
Copy link
Contributor

@kmeleta kmeleta Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mobile logic is improved, which is important because there's a pretty big range images can render at between 0 and 750px. But the 990px breakpoint is still a static number and will usually render too large of an image, with the worst case scenario being a viewport width closer to 990 with a page_width set closer to 1600.

I mentioned the strategy we use in other sections here but something like this is more or less what I would expect.

(min-width: {{ settings.page_width }}px) {{ settings.page_width | divided_by: num_columns }}px,
(min-width: 990px) calc((100vw - desktop_padding?) / {{ num_columns }} * {{ image_width }}),
(min-width: 750px) calc((100vw - mobile_padding?) / {{ num_columns_mobile }} * {{ image_width }}),
calc(100vw / {{ num_columns_mobile }} * image_width)

If we're not going to factor any padding values into these calculations, we can probably skip the 750px breakpoint, but I think we should definitely improve the larger breakpoints somehow at least.

Copy link
Contributor Author

@eugenekasimov eugenekasimov Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, what you are trying to say is that when the page-width is set to 1600px and a view port of the screen is smaller we are not really efficient. Is that right?
That's a good catch @kmeleta . I'm going to fix it but still skip the 750px. Does it sound good to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bottomline is if we can get good results without accounting for paddings, then we don't need to consider them and enjoy the simpler logic. The desktop and tablet page paddings are 50px (100px total), the gaps between columns can be between 4px and 40px (40px * (num_columns - 1) or 200px worst case total). So in theory, under some conditions there could be a calculated discrepancy of up to ~300px.

Here's an example factoring in more grid spacing. Pretty inaccurate result, but of ourse with 6 columns the general image sizes are at least smaller. What's your feeling?

Copy link
Contributor Author

@eugenekasimov eugenekasimov Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed everything again and decided to add paddings. I think it's worth it. Now I feel we are quite precise in the calculations even though I had to hardcode some of the padding values.

{% endcapture %}
{{
block.settings.image
| image_url: width: 1420
| image_url: width: max_image_width
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved
| image_tag:
loading: 'lazy',
widths: '50, 75, 100, 150, 200, 300, 400, 500, 750, 1000, 1500, 2000, 2500, 3000',
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved
sizes: sizes,
widths: '275, 550, 710, 1420',
class: 'multicolumn-card__image'
}}
</div>
Expand Down