html5 video play by scrolling with the mouse wheel

后端 未结 5 983
無奈伤痛
無奈伤痛 2020-12-30 06:43

I want to be able to make a web page that plays a video forward and backward when they scroll with the mouse wheel up and down. It seems conceivable, via HTML5 and possibly

5条回答
  •  攒了一身酷
    2020-12-30 06:50

    Some mods from my end to make it smoother

    // select video element
    var vid = document.getElementById('v0');
    //var vid = $('#v0')[0]; // jquery option
    
    // pause video on load
    vid.pause();
    
    // pause video on document scroll (stops autoplay once scroll started)
    window.onscroll = function(){
        vid.pause();
    };
    
    // refresh video frames on interval for smoother playback
    setInterval(function(){
      TweenMax.to(vid,2,{currentTime:window.pageYOffset/400});
    }, 40);
    

    http://codepen.io/anon/pen/qORmee

提交回复
热议问题