lazyload video tag

PHOTO EMBED

Sun Dec 29 2024 08:46:22 GMT+0000 (Coordinated Universal Time)

Saved by @alexlam #css

{% comment %}
Capture the original video tag and replace attributes so they become data-attributes,
then inject a .lazy class for yall.
{% endcomment %}

{% capture video_tag %}
  {{ block.settings.video | video_tag: image_size: '1920x', autoplay: false, loop: true, muted: true }}
{% endcapture %}

{% assign lazy_video_tag = video_tag 
  | replace: 'src="', 'data-src="'
  | replace: 'poster="', 'data-poster="'
  | replace: '<video', '<video class="lazy" '
%}

{{ lazy_video_tag }}
 
  <script type="module">
    import { yall } from "https://cdn.jsdelivr.net/npm/yall-js@4.0.2/dist/yall.min.js";
    yall();
  </script>
content_copyCOPY