Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function updateVideoSource(event) {
- // Get a reference to the video element
- const video = document.getElementsByTagName('video');
- if (video && video[0]) {
- const currentSrc = video[0].getAttribute('src');
- const smallVideoSrc = "https://projekt-login.de/wp-content/uploads/2023/10/4d-werk_comp_9x16.mp4";
- const largeVideoSrc = "https://projekt-login.de/wp-content/uploads/2023/09/4d-werk_home.mp4";
- if (event.matches) {
- // If the screen width is less than 768 pixels, use the small video
- if (currentSrc !== smallVideoSrc) {
- video[0].setAttribute('src', smallVideoSrc);
- }
- } else {
- // If the screen width is 768 pixels or more, use the large video
- if (currentSrc !== largeVideoSrc) {
- video[0].setAttribute('src', largeVideoSrc);
- }
- }
- }
- }
- const mqVideo = window.matchMedia('(max-width: 767px)');
- // BC for old Safari
- if (typeof mqVideo.addEventListener === 'function') {
- mqVideo.addEventListener('change', updateVideoSource);
- } else {
- mqVideo.addListener(updateVideoSource);
- }
- // Initial set
- updateVideoSource({matches: mqVideo.matches});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement