mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-18 21:10:57 +08:00
24 lines
650 B
JavaScript
24 lines
650 B
JavaScript
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);
|
|
});
|
|
}
|