I have two videos that I'm trying to use for a cinemagraph - trees on the loop in the background and the video of a dog moving just once in the front. I've cut the dog video and wanted to place it over the background, but I have trouble aligning the cut video for it to resize properly on various screens. Does anyone have any suggestions on how to go about this? Maybe there is a way to do that in js?
// fallback: show controls if autoplay fails // (needed for Samsung Internet for Android, as of v6.4) window.addEventListener('load', async() => { let video = document.querySelector('video[muted][autoplay]'); try { await video.play(); } catch (err) { video.controls = true; } }); var video = document.getElementById("videob"); video.addEventListener("canplay", function() { setTimeout(function() { video.play(); }, 5000); });
video { max-width: 100%; position: absolute; top: 0; left: 0; } #video { position: absolute; top: 0; left: 0; } #overlay { position: absolute; top: 0; left: 0; opacity: 0.4; }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <div class="container"> <video poster="https://aiimblabs.com/j/still.jpg" id="videob" preload="true" src="https://aiimblabs.com/j/dog.mp4" muted autoplay> </video> <video poster="https://aiimblabs.com/j/still.jpg" id="overlay" src="https://aiimblabs.com/j/tree.mp4" muted autoplay loop> </video> </div>
You need to assign a width and height to the videos
video {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
In case you want the videos to cover the screen add the following line:
object-fit: cover;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.