Skip to content

Commit

Permalink
Switch to uing <picture> for responsive images
Browse files Browse the repository at this point in the history
  • Loading branch information
alshedivat authored and siantonelli committed Oct 26, 2024
1 parent 40b2c16 commit bf4a8e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ enable_project_categories: false # enables categorization of projects into
enable_medium_zoom: true # enables image zoom feature (as on medium.com)
enable_progressbar: true # enables a horizontal progress bar linked to the vertical scroll position


# -----------------------------------------------------------------------------
# Library versions
# -----------------------------------------------------------------------------
Expand Down
14 changes: 6 additions & 8 deletions _includes/responsive_img.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% assign largest = resized | sort: 'width' | last %}
{% capture srcset %}
{% for i in resized %}
{{ i.path | relative_url }} {{ i.width }}w,
{% endfor %}
{% endcapture %}

<img {% if class %}class="{{ class }}"{% endif %} src="{{ largest.path | relative_url }}" srcset="{{ srcset | strip_newlines }} {{ path | relative_url }} {{ original.width }}w" {% if alt %}alt="{{ alt }}"{% endif %} {% if title %}title="{{ title }}"{% endif %} {% if zoomable %}data-zoomable{% endif %}/>
<picture>
{% for i in resized %}
<source media="(max-width: {{ i.width }}px)" srcset="{{ i.path | relative_url }}">
{% endfor %}
<img {% if class %}class="{{ class }}"{% endif %} src="{{ path | relative_url }}" {% if alt %}alt="{{ alt }}"{% endif %} {% if title %}title="{{ title }}"{% endif %} {% if zoomable %}data-zoomable{% endif %} />
</picture>

0 comments on commit bf4a8e8

Please sign in to comment.