[英]Esc function does not get called when exiting fullscreen mode
I have some content which I am making fullscreen.我有一些正在制作全屏的内容。
What I want is to fire a function on pressing Esc which exits the fullscreen.我想要的是在按下 Esc 时触发一个退出全屏的功能。 Please go through the below link: https://stackblitz.com/edit/angular-zk6udf
请通过以下链接: https : //stackblitz.com/edit/angular-zk6udf
Please Note: Kindly open the execution window in a new window by clicking请注意:请单击以在新窗口中打开执行窗口
in order to properly see the fullscreen mode.
为了正确地看到全屏模式。
In above, when I click the button it enters in fullscreen.在上面,当我点击按钮时,它进入全屏。 But when I press Esc, the hidden text doesn't show up.
但是当我按 Esc 时,隐藏的文本不会出现。 Instead when I press Esc again, then it does that.
相反,当我再次按 Esc 时,它会这样做。 I am using HostListener for achieving this.
我正在使用 HostListener 来实现这一点。
How can I achieve calling a function on pressing Esc which exits the fullscreen?如何在按 Esc 退出全屏时调用函数?
Thanks.谢谢。
Instead listen to fullscreenchange
in your hostlistener:而是在您的主机侦听器中收听
fullscreenchange
:
@HostListener("document:fullscreenchange", ["$event"]) onKeydownHandler(
event: KeyboardEvent
) {
// has exited
if (!document.fullscreenElement) {
this.showTextAfterEscape = true;
}
}
Your STACKBLITZ你的STACKBLITZ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.