html5 scrolling,javascript - HTML5 video, pause while scrolling - Stack Overflow

作者分享了如何在HTML5视频作为网页背景时,通过鼠标滚轮控制视频暂停和继续播放的技术问题。他们尝试让视频在滚动时暂停,直到达到特定位置才恢复播放,但遇到视频会在暂停点开始而非从上次暂停点续播的问题。代码展示了作者尝试的解决方案和遇到的挑战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm building an HTML5 video as background which plays with the mouse wheel like this excellent example.

Now I want to enhance it by pausing it while still scrolling then start to play it again after I've scrolled for a certain amount. I've tried but the problem is that it jumps on the point where it supposed to be if I hadn't paused it rather than continuing from where I've paused.

Here's my code:

$(function () {

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();

//console.log(vid.currentTime, window.pageYOffset / 400);

$("#time").text(vid.currentTime);

};

// refresh video frames on interval for smoother playback

setInterval(function () {

if((window.pageYOffset / 400) > 3 && (window.pageYOffset / 400) < 6){

vid.pause();

} else {

vid.currentTime = window.pageYOffset / 400;

}

}, 32);

});

Is there a way of achieving that?

Thanks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值