let videoLoaded = false function preLoadVideo(myVid) { let r = new XMLHttpRequest(); r.onload = function() { videoLoaded = true myVid.src = URL.createObjectURL(r.response); }; if (myVid.canPlayType('video/webm')) { r.open("GET", "static/img/general/videos/eth-video-2.webm"); } else { r.open("GET", "static/img/general/videos/eth-video-2.mp4"); } r.responseType = "blob"; r.send(); } document.addEventListener("DOMContentLoaded", function () { const mainVideo2 =document.getElementById('main-screen-video2') // preLoadVideo(mainVideo2) const mainVideo = document.getElementById('main-screen-video') let mainVideoEnded = false; mainVideo.onended = function( ) { mainVideoEnded = true mainVideo2.play(); mainVideo2.classList.add('active') } if (!mainVideo.playing && !mainVideoEnded) { mainVideo.play() } })