pausing and playing multiple HTML5 videos using jQuery get(0) indexing?

前端 未结 3 1320
后悔当初
后悔当初 2021-02-11 01:44

I have a page of several videos. One can click a thumbnail to play each video. The problem is for that for greater than 2 videos, the clicking on the 3rd thumbnail doesn\'t paus

3条回答
  •  囚心锁ツ
    2021-02-11 02:08

    Easy solution to play only one HTML5 video element on page using JQUERY:

    $(function() {
    $("video").each(function() {
        this.pauseOthers = function(event) {
            $('video').addClass('stopvideo');
            $(this).removeClass('stopvideo');
            $('.stopvideo').each(function() {
                this.pause();
            });
        };
        this.addEventListener("play", this.pauseOthers.bind(this), false);
    });
    });
    

提交回复
热议问题