我正在寻找一种在 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/