Prevent HTML5 videos from downloading the files on mobile - videojs

前端 未结 3 1354
一个人的身影
一个人的身影 2021-02-02 10:56

So I\'m currently building a website that has a carousel containing four videos, each video is triggered to play by hooking in to the Bootstrap 3 carousel\'s slide.bs.caro

3条回答
  •  爱一瞬间的悲伤
    2021-02-02 11:19

    Based on Ian and GDGR's answers, I modified this to work for multiple videos.

    
    

    if (window.innerWidth > 730) {   
        // get multiple videos
        var sources = document.querySelectorAll('video.mobile-no-load'); 
        // loop through the videos
        sources.forEach(function(source){ 
            // target the src attribute of the  element and set it to the data-src attribute
            source.childNodes[1].setAttribute('src', source.childNodes[1].getAttribute('data-src'))
        }); 
    }

提交回复
热议问题