鼠标滚轮滚动HTML5视频jQuery

Mousewheel Scroll HTML5 Video jQuery

本文关键字:视频 jQuery HTML5 滚动 鼠标      更新时间:2023-09-26

我希望能够使用鼠标滚轮控制我的视频。到目前为止,我已经做到了。我正沿着mac pro网站的路线前进。我将它绑定到鼠标滚轮上,当用户向下滚动时,它就开始播放。

我想做的是,在达到特定间隔时停止视频,比如2秒。然而,由于帧的长度,视频可能会跳过这一点,即从1.98到2.05…

为了解决这个问题,我使用了Math。地板上的功能。然而,随之而来的是另一个问题——这种情况会多次发生。

有没有人对更好的解决方案有任何想法,比如阈值函数?

        // Do stuff when specific time intervals are reached
        $(video).on('timeupdate', function() {
            if (Math.floor(video.currentTime) == 2){
                video.pause();
                console.log("Pausing video... ");
            }
            else if(video.ended){
                // Move to next section
                return true;
            }
        });

你不能用>=比较代替检查地板时间吗?

            if (video.currentTime >= 2){
                video.pause();
                console.log("Pausing video... ");
            }
            else if(video.ended){
                // Move to next section
                return true;
            }