mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-17 20:40:58 +08:00
feat: handle ios safari keyboard
This commit is contained in:
@@ -12,6 +12,7 @@ import { checkToken, clearToken, isLogin } from './utils/auth'
|
||||
import { loginWithGoogle } from './utils/google'
|
||||
import { initTheme } from './utils/theme'
|
||||
import { clearVditorStorage } from './utils/clearVditorStorage'
|
||||
import { initIOSKeyboardFix } from './utils/iosKeyboardFix'
|
||||
|
||||
// 采用本地开发环境
|
||||
// export const API_DOMAIN = 'http://127.0.0.1'
|
||||
@@ -34,6 +35,7 @@ export const toast = useToast()
|
||||
|
||||
initTheme()
|
||||
clearVditorStorage()
|
||||
initIOSKeyboardFix()
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
|
||||
23
frontend/src/utils/iosKeyboardFix.js
Normal file
23
frontend/src/utils/iosKeyboardFix.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export function initIOSKeyboardFix() {
|
||||
if (typeof window === 'undefined' || !window.visualViewport) return;
|
||||
|
||||
const ua = navigator.userAgent || '';
|
||||
const isIOS = /iP(ad|hone|od)/.test(ua);
|
||||
if (!isIOS) return;
|
||||
|
||||
const viewport = window.visualViewport;
|
||||
const adjustScroll = () => {
|
||||
window.scrollTo(0, viewport.offsetTop);
|
||||
};
|
||||
|
||||
viewport.addEventListener('resize', adjustScroll);
|
||||
viewport.addEventListener('scroll', adjustScroll);
|
||||
|
||||
let lastScrollY = 0;
|
||||
document.addEventListener('focusin', () => {
|
||||
lastScrollY = window.scrollY;
|
||||
});
|
||||
document.addEventListener('focusout', () => {
|
||||
window.scrollTo(0, lastScrollY);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user