Guest User

videobannercode

a guest
Dec 4th, 2023
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. {% if section.settings.video %}
  2. {%- liquid
  3. assign video_id = section.settings.video.id | default: section.settings.video_url.id
  4. assign video_alt = section.settings.video.alt | default: section.settings.description
  5. assign alt = 'sections.video.load_video' | t: description: video_alt | escape
  6. assign poster = section.settings.video.preview_image | default: section.settings.cover_image
  7. if section.settings.cover_image
  8. assign poster = section.settings.cover_image
  9. endif
  10. if section.settings.video != null
  11. assign ratio_diff = section.settings.video.aspect_ratio | minus: poster.aspect_ratio | abs
  12. if ratio_diff < 0.01 and ratio_diff > 0
  13. assign fix_ratio = true
  14. endif
  15. endif
  16. -%}
  17. <video playsinline autoplay muted loop poster="{{ poster | image_url: width: 3840 }}" style="width: 100%; height: 100%; object-fit: cover;" id="video-{{ section.id }}">
  18. <source src="{{ section.settings.video.sources[1].url }}" type="video/mp4">
  19. Your browser does not support the video tag.
  20. </video>
  21.  
  22. <style>
  23. div#shopify-section-template--16108370624665__6a9abf06-1dde-4645-9360-ddbb03a13b7b {
  24. display: flex;
  25. align-items: center;
  26. }
  27.  
  28. </style>
  29. <script>
  30. function getDivDimensionsByClassMakka(className, ratio) {
  31. var elements = document.querySelector(className)
  32.  
  33. if (elements) {
  34. var width = elements.offsetWidth;
  35. var height = width / ratio;
  36.  
  37. return { width: width, height: height };
  38. } else {
  39. // Handle the case where no element with the specified class is found
  40. console.error("No element found with class: " + className);
  41. return null;
  42. }
  43. }
  44.  
  45. // Example usage with a ratio of 1.75
  46. var ratio = {{ section.settings.video.aspect_ratio }};
  47. var dimensions = getDivDimensionsByClassMakka("#video-{{ section.id }}", ratio);
  48.  
  49. if (dimensions) {
  50. document.querySelector('#video-{{ section.id }}').style.minHeight = `${Math.round(dimensions.height - 10)}px`
  51. }
  52.  
  53. window.onresize = function(){
  54. var dimensions = getDivDimensionsByClassMakka("#video-{{ section.id }}", ratio);
  55. if (dimensions) {
  56. document.querySelector('#video-{{ section.id }}').style.minHeight = `${Math.round(dimensions.height)}px`
  57. }
  58. };
  59. </script>
  60.  
  61.  
  62. {% endif %}
  63. {% schema %}
  64. {
  65. "name": "Full Width Video",
  66. "settings": [
  67. {
  68. "type": "image_picker",
  69. "id": "cover_image",
  70. "label": "t:sections.video.settings.cover_image.label"
  71. },
  72. {
  73. "type": "video",
  74. "id": "video",
  75. "label": "Video"
  76. }
  77. ],
  78. "presets": [
  79. {
  80. "name": "Full Width Video"
  81. }
  82. ]
  83. }
  84. {% endschema %}
  85.  
  86. {% stylesheet %}
  87. {% endstylesheet %}
  88.  
  89. {% javascript %}
  90. {% endjavascript %}
Advertisement
Add Comment
Please, Sign In to add comment