gpt4 book ai didi

javascript - 使用 .play() 按回车键播放/暂停视频

转载 作者:行者123 更新时间:2023-11-30 08:59:20 24 4
gpt4 key购买 nike

我正在寻找一种在 Chrome 中启动和停止 HTML 5 视频的方法(我正在使用 impress.js,因此它只需要在 Chrome 中工作),方法是按回车键.

我知道它与 .play() 函数有关,但我是 JavaScript 的新手。

有人可以给我提示吗?

最佳答案

var video = document.getElementById('video-element-id-here');

document.onkeypress = function(e) {
if ( (e || window.event).keyCode === 13 /* enter key */ ) {
video.paused ? video.play() : video.pause();
}
};

OP:也请看评论。

关于javascript - 使用 .play() 按回车键播放/暂停视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10638408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com