Следующий код для скрытия / отображения элемента заголовка, основанного на пользовательской прокрутке, кажется, работает нормально в большинстве основных браузеров на Windows PC, MacOS и на Android, но совсем не работает в iOS.Я озадачен тем, почему это может быть.Я пытался определить проблему, но не смог.Любая помощь с благодарностью!Код выглядит следующим образом:
let scrollPosition = window.scrollY;
let topgun = document.querySelector('header')
topgun.style.position = 'absolute'
topgun.style.top = scrollPosition + 'px'
window.addEventListener('scroll', function (e) {
let tgrect = topgun.getBoundingClientRect()
if (window.scrollY < scrollPosition) {
if(-tgrect.top > tgrect.height){
topgun.style.top = (window.scrollY - tgrect.height) + 'px'
}else if(tgrect.top > 0){
topgun.style.top = '0px'
topgun.style.position = 'fixed'
}
} else {
if (topgun.style.position == 'fixed') {
topgun.style.top = (window.scrollY + tgrect.top) + 'px'
topgun.style.position = 'absolute'
}
}
scrollPosition = window.scrollY
})
Чтобы увидеть код с реальным HTML и CSS: https://codepen.io/quinlo/pen/yQGOKp