Skip to content

Instantly share code, notes, and snippets.

@ankedsgn
Created July 17, 2020 08:07
Show Gist options
  • Save ankedsgn/5e9f11df8bb32b21be8a047bf6a6c69c to your computer and use it in GitHub Desktop.
Save ankedsgn/5e9f11df8bb32b21be8a047bf6a6c69c to your computer and use it in GitHub Desktop.
ratiobox
figure.ratio-box {
height: 0;
position: relative;
background: var(--lightGrey);
padding-top: 100%; //default. Correct padding is calculated and set inline in the module
img {
position: absolute;
top: 0;
}
}
{% set imageinfo = imageinfo(item.image.file) %}
{% set ratiopct = (imageinfo.info.height / imageinfo.info.width * 100)|replace(',','.') %}
{# {{ ratiopct }} #}
<!-- {{ item.block }} -->
<div class="component-image">
<figure class="ratio-box"
{% if ratiopct is not empty %} style="padding-top: {{ ratiopct }}%" {% endif %}>
<img
loading="lazy"
data-zoomable
data-zoom-src="{{ item.image.file|thumbnail(2000, 2000, 'r') }}"
sizes=" (min-width: 1350px) 700px,
(min-width: 1024px) 50vw,
85vw"
srcset="{{ item.image.file|thumbnail(800, 2000, 'r') }} 800w,
{{ item.image.file|thumbnail(400, 1000, 'r') }} 400w"
src="{{ item.image.file|thumbnail(800, 2000, 'r') }}" alt="{{ item.image.alt }}">
<figcaption>{{ item.image.caption }}</figcaption>
</figure>
</div>
<!-- /{{ item.block }} -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment