網(wǎng)站首頁 編程語言 正文
全屏監(jiān)聽Esc鍵
全屏與退出全屏
if (isFull) {
? ? ? document.exitFullscreen();
? ? } else {
? ? ? tree.current.requestFullscreen();
? ? ? tree.current.style.width = '100%'
? ? }
? };
監(jiān)聽退出全屏事件
退出方式有兩種:
- 1.通過上面的requestFullscreen。
- 2.通過按esc退出
問題:通過requestFullscreen操作可以修改數(shù)據(jù)狀態(tài),但當(dāng)用戶按esc鍵時,是監(jiān)聽不到的。
采用如下方式:?
const escFunction = () => {
setFull((prevFill) => !prevFill);
}
useEffect(() => {
// 監(jiān)聽退出全屏事件 --- chrome 用 esc 退出全屏并不會觸發(fā) keyup 事件
document.addEventListener("webkitfullscreenchange", escFunction); /* Chrome, Safari and Opera */
document.addEventListener("mozfullscreenchange", escFunction); /* Firefox */
document.addEventListener("fullscreenchange", escFunction); /* Standard syntax */
document.addEventListener("msfullscreenchange", escFunction); /* IE / Edge */
return () => {
//銷毀時清除監(jiān)聽
document.removeEventListener("webkitfullscreenchange", escFunction);
document.removeEventListener("mozfullscreenchange", escFunction);
document.removeEventListener("fullscreenchange", escFunction);
document.removeEventListener("MSFullscreenChange", escFunction);
}
}, []);
React添加監(jiān)聽事件 監(jiān)聽鍵盤事件
react添加監(jiān)聽事件監(jiān)聽鍵盤事件
參考:
記錄下確認(rèn)框confirm代碼:
原文鏈接:https://blog.csdn.net/Snow_GX/article/details/115203076
相關(guān)推薦
- 2022-11-17 React狀態(tài)管理Redux的使用介紹詳解_React
- 2023-01-01 Echarts改變柱狀圖顏色
- 2022-04-09 在Mybatis中使用自定義緩存ehcache
- 2022-10-06 react-router-dom入門使用教程(路由的模糊匹配與嚴(yán)格匹配)_React
- 2022-04-01 numpy array保存為.nii.gz格式
- 2023-10-31 IP地址、網(wǎng)關(guān)、網(wǎng)絡(luò)/主機號、子網(wǎng)掩碼關(guān)系
- 2022-12-23 C語言例題之輸出1000以內(nèi)的所有完數(shù)_C 語言
- 2022-04-14 zsh: command not found:快速的解決方法
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支