<div class="videoImg-wraper bg-video">
    <img class="img-fluid" src="/images/animated-img.png" alt="animated-img" data-scroll-zoom />
    <video role="video" src="https://media.istockphoto.com/videos/industrial-abstract-pattern-video-id1050190380" alt="Video" muted autoplay loop data-scroll-zoom></video>
</div>
<div class="videoImg-wraper {{ videoSrc ? 'bg-video' : 'bg-img' }}">
  {% if imgSrc %}
      <img class="img-fluid" src ="{{imgSrc}}" alt="animated-img" data-scroll-zoom/>
  {% endif %}
  {% if videoSrc %}
    <video  role="video" src="{{videoSrc}}" alt="Video" muted autoplay loop data-scroll-zoom></video>
  {% endif %}
</div>
{
  "videoSrc": "https://media.istockphoto.com/videos/industrial-abstract-pattern-video-id1050190380",
  "imgSrc": "/images/animated-img.png"
}
  • Content:
    import $ from "jquery";
    
    $(document).ready(function() {
      let scaleAmount = 0.3;
    
      function scrollZoom() {
        const images = document.querySelectorAll("[data-scroll-zoom]");
        let scrollPosY = 0;
        scaleAmount = scaleAmount / 100;
    
        const observerConfig = {
          rootMargin: "0% 0% 0% 0%",
          threshold: 0
        };
    
        images.forEach(image => {
          let isVisible = false;
          const observer = new IntersectionObserver((elements, self) => {
            elements.forEach(element => {
              isVisible = element.isIntersecting;
            });
          }, observerConfig);
    
          observer.observe(image);
    
          // Set initial image scale on page load
          image.style.transform = `scale(${1 +
            scaleAmount * percentageSeen(image)})`;
    
          window.addEventListener("scroll", () => {
            if (isVisible) {
              scrollPosY = window.pageYOffset;
              image.style.transform = `scale(${1 +
                scaleAmount * percentageSeen(image)})`;
            }
          });
        });
    
        function percentageSeen(element) {
          const parent = element.parentNode;
          const viewportHeight = window.innerHeight;
          const scrollY = window.scrollY;
          const elPosY = parent.getBoundingClientRect().top + scrollY;
          const borderHeight =
            parseFloat(
              getComputedStyle(parent).getPropertyValue("border-bottom-width")
            ) +
            parseFloat(
              getComputedStyle(element).getPropertyValue("border-top-width")
            );
          const elHeight = parent.offsetHeight + borderHeight;
    
          if (elPosY > scrollY + viewportHeight) {
            return 0;
          } else if (elPosY + elHeight < scrollY) {
            return 100;
          } else {
            const distance = scrollY + viewportHeight - elPosY;
            let percentage = distance / ((viewportHeight + elHeight) / 100);
            percentage = Math.round(percentage);
    
            return percentage;
          }
        }
      }
    
      scrollZoom();
    });
    
  • URL: /components/raw/animated_element/animated_element.js
  • Filesystem Path: components/03-components/animated_element/animated_element.js
  • Size: 1.9 KB
  • Content:
    .videoImg-wraper {
      overflow: hidden;
      &.bg-img {
        video {
          display: none;
        }
      }
      &.bg-video {
        img {
          display: none;
        }
      }
      img {
        width: 100%;
        height: 240px;
      }
      video {
        width: 100%;
        height: 240px;
        object-fit: cover;
      }
    }
    
  • URL: /components/raw/animated_element/animated_element.scss
  • Filesystem Path: components/03-components/animated_element/animated_element.scss
  • Size: 274 Bytes
  • Handle: @animated_element
  • Preview:
  • Filesystem Path: components/03-components/animated_element/animated_element.twig

There are no notes for this item.