无法暂停视频

问题描述 投票:0回答:1
let video = document.querySelector(".reel video");

video.addEventListener("click", function () {
    console.log("Video clicked"); // Add console log to check if the event listener is triggered
    video.pause();
    video.style.height = "0%";
    video.style.width = "0%";
    document.exitFullscreen();
    console.log("Video paused"); // Add console log to check if video is paused
});

我想通过单击屏幕上任何位置的视频来暂停视频每行代码都正常工作我检查了所有行,但我无法暂停视频

javascript video playback pause
1个回答
0
投票

试试这个:

let video = document.querySelector(".reel video");

if (video) {
    video.addEventListener("click", function () {
        console.log("Video clicked");
        if (!video.paused) {
            video.pause();
            video.style.height = "0%";
            video.style.width = "0%";
            if (document.fullscreenElement) {
                document.exitFullscreen();
            }
            console.log("Video paused and hidden"); 
        } else {
            console.log("Video was already paused when clicked"); 
        }
    });
} else {
    console.log("Video element not found");
}
© www.soinside.com 2019 - 2024. All rights reserved.