【发布时间】:2021-11-10 13:00:48
【问题描述】:
我可以禁用嵌入 Vimeo 视频的某些键盘快捷键而不是禁用所有快捷键吗?
我经常通过 iframe 将 Vimeo 视频嵌入我的网站以进行视频会议。 我需要隐藏控制栏并禁用除快捷方式“F”以外的所有快捷方式
有没有办法做到这一点?
谢谢
【问题讨论】:
标签: javascript iframe vimeo vimeo-api vimeo-player
我可以禁用嵌入 Vimeo 视频的某些键盘快捷键而不是禁用所有快捷键吗?
我经常通过 iframe 将 Vimeo 视频嵌入我的网站以进行视频会议。 我需要隐藏控制栏并禁用除快捷方式“F”以外的所有快捷方式
有没有办法做到这一点?
谢谢
【问题讨论】:
标签: javascript iframe vimeo vimeo-api vimeo-player
请通过本地保存在您的设备上或使用任何第三方代码编译器尝试代码,因为 Stack Overflow 不允许“全屏”,并确保 iframe 处于活动状态或焦点。
var options = {
id: 59777392, //Video Id
width: 640,
keyboard: false,
};
var player = new Vimeo.Player('VimeoVideo', options);
player.on('play', function() {
window.focus()
});
player.on('pause', function() {
window.focus()
});
window.addEventListener("blur", () => {
{
if (document.activeElement.tagName === "IFRAME") {
check(); //Checks if Iframe is already in Full Screen
}
};
});
function check(){
if(window.innerHeight !== screen.height) { //If the Iframe is not full screen then make it full screen when user presses 'F', this will work only after the Vimeo Video Iframe has completed loading.
document.addEventListener("keydown", event => {
if (event.isComposing || event.keyCode !== 70) {
return;
}
player.requestFullscreen();
})}
else{
document.addEventListener("keydown", event => {//If the Iframe is in full screen then make it normal, this function might not be executed if user do not interacts.
if (event.isComposing || event.keyCode !== 70) {
return;
}
player.exitFullscreen();
})
}
}
<!-- The Keyboard is disbaled and only 'F' key is enabled -->
<div id="VimeoVideo"></div>
<script src="https://player.vimeo.com/api/player.js"></script>
【讨论】: