gpt4 book ai didi

javascript - 在 Reveal.js 中使用空格键播放/暂停视频

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

我正在使用 Reveal.js 演示一些短视频剪辑(每张幻灯片 1 个剪辑)。 Reveal.js 演示文稿的默认设置允许使用左/右箭头键在幻灯片之间导航。我想使用空格键(key = 32)来播放/暂停视频,因此我尝试更改/覆盖reveal.js中的默认键盘绑定(bind)。 https://github.com/hakimel/reveal.js/建议如下:

Reveal.configure({
keyboard: {
32: function() {}
}
});

我尝试插入多个代码/函数,但是当我尝试在浏览器上运行代码时,要么出现黑屏,要么什么也没有发生。

var video = document.getElementById('video');
var $video = $('video');

$(window).keydown(function(e) {
if (e.keyCode === 32) {
if (video.paused == true)
video.play();
else
video.pause();
}
});

如您所见,我是 JS/reveal.js 的绝对初学者,非常感谢您的帮助。谢谢!

最佳答案

这将解决您的问题:

Reveal.initialize({
// Enable keyboard shortcuts for navigation
keyboard: true,
}

对于自定义键盘事件:

Reveal.configure({
keyboard: {
13: 'next', // go to the next slide when the ENTER key is pressed
27: function() {}, // do something custom when ESC is pressed
32: function(){
if (video.paused == true) video.play();
else video.pause();
}
}
}
});

关于javascript - 在 Reveal.js 中使用空格键播放/暂停视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30374241/

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