Answer the question
In order to leave comments, you need to log in
Video for desktop, picture for mobile?
Hello everyone ;)
I have a short question:
A simple video is played in the header of the site using the following code:
<video id="video_1" width="100%" height="100%" loop autoplay>
<source type="video/mp4" src="/video/2.mp4" />
<source type="video/webm" src="/video/2.mp4" />
</video>
Answer the question
In order to leave comments, you need to log in
Of course, I could be wrong, and I need to check this.
But as far as I remember, display none doesn't hide elements from loading and rendering.
Those. the browser will still get them, no matter if the video is hidden or not.
Therefore, I have only one suggestion.
Dynamically, depending on the screen size, using jQuery to create a DOMa element.
In this case, the extra traffic will definitely not be loaded.
Since the script simply will not process its action.
Upd:
I checked, and it's true, display none does not affect the loading in any way.
The video is still loaded, but already in the background and eating traffic.
jQuery(document).ready(function(){
var w = screen.width;
if (w >= '1000') {
$('.fullscreen-bg__video').append('<source src="video/video.webm" type="video/webm">');
} else {
if (w < '1000') {
$('.fullscreen-bg__video').append('<div id="third">Картинка</div>');
}
}
});
<video id="video_1" width="100%" height="100%" loop autoplay>
</video>
jQuery(document).ready(function(){
var w = screen.width;
if (w >= '1000') {
$('#video_1').append('<source type="video/mp4" src="/video/2.mp4" /><source type="video/webm" src="/video/2.mp4" />'); // в блок с ID video_1 добавляем код вставки видео
} else {
if (w < '1000') {
$('#video_1').append('<div class="image"><img src="img/video.jpg" alt=""></div>'); // тут нужно прописать путь до картинки и название дива, который создается
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question