Created
March 22, 2019 08:27
-
-
Save webag/2d7bab28d0e5c723ff01a3dc9b6ed40a to your computer and use it in GitHub Desktop.
Video html5 js inset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video loop muted autoplay id="head_video"> | |
<source src="" type="video/webm" id="source_webm"> | |
<source src="" type="video/mp4" id="source_mp4"> | |
</video> | |
<script> | |
var aboutHeaderCheck = function() { | |
var aboutHeader = document.querySelector('.s-about-head'); | |
var video = document.getElementById("head_video"); | |
var video_mp4 = document.getElementById("source_mp4"); | |
var video_webm = document.getElementById("source_webm"); | |
var mp4Src = "/img/video.mp4"; | |
var webmSrc = "/img/video.webm"; | |
if (window.matchMedia("(max-width: 1025px)").matches) { | |
aboutHeader.classList.remove('s-about-head--video'); | |
aboutHeader.classList.add('s-about-head--photo'); | |
if (document.body.contains(video)) { | |
video.parentNode.removeChild(video); | |
} | |
} else { | |
if (document.body.contains(video) && video_mp4.getAttribute('src') === ""){ | |
video_mp4.setAttribute('src',mp4Src); | |
video_webm.setAttribute('src',webmSrc); | |
video.load(); | |
video.play(); | |
} | |
} | |
}; | |
aboutHeaderCheck(); | |
window.addEventListener('resize',aboutHeaderCheck); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment