fix(FullScreenButton): update fullscreen state icon (#4642)

* fix: update fullscreen state icon

* refactor: 重构代码提高可读性
This commit is contained in:
Argo Zhang 2024-11-10 21:22:06 -08:00 committed by GitHub
parent cf8e25ca72
commit a4084e7b82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,7 @@ export async function toggle(options) {
if (el !== null) {
if (isFullscreen()) {
await document.exitFullscreen()
await exitFullscreen(el);
}
else {
await enterFullscreen(el);
@ -25,12 +25,22 @@ export async function toggle(options) {
const enterFullscreen = async el => {
await el.requestFullscreen();
if (!isFullscreen()) {
el.classList.remove('bb-fs-open');
document.documentElement.classList.remove('bb-fs-open');
updateFullscreenState(el);
}
const exitFullscreen = async el => {
await document.exitFullscreen()
updateFullscreenState(el);
}
const updateFullscreenState = el => {
if (isFullscreen()) {
el.classList.add('bb-fs-open')
}
else {
el.classList.add('bb-fs-open')
el.classList.remove('bb-fs-open');
document.documentElement.classList.remove('bb-fs-open');
}
}