Thanks to this answer, I use video[poster]{object-fit:fill}
in my css to avoid distorted poster images in html5 videos. Since poster
seems stylable, I also want to use css to display different posters for a video, depending on screensize (mobile or desktop). But video[poster]{background-image:url(poster.jpg)
doesn't produce any result, presumably poster
is not a background. So I tried adapting some javascript found here, as follows:
function myFunction(x) {
if (x.matches) { // If media query matches
document.getElementById("video").poster = "poster1.jpg";
} else {
document.getElementById("video").poster = "poster2.jpg";
}
}
var x = window.matchMedia("(max-width: 700px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction)
It doesn't work either, but maybe it's just missing some little thing (even the original fails javascript validation) Anybody know how to apply media queries to the poster property?