$(function() { const autoplayVideos = $('.knk-autoplay .et_pb_video_box'); if (autoplayVideos.length) { autoplayVideos.find('video').prop('muted', true) .attr({ loop: 'loop', playsInline: '' }); const observerOptions = { root: null, rootMargin: '0px', threshold: 0.5 }; const videoObserver = new IntersectionObserver((entries, observer) => { entries.forEach((entry) => { entry.isIntersecting ? entry.target.play() : entry.target.pause(); }); }, observerOptions); autoplayVideos.each(function() { videoObserver.observe($(this).find('video')[0]); }); } });