Answer the question
In order to leave comments, you need to log in
Why does transform scale on iPhone not work well on scroll?
Good day. In general, the problem was uploaded to yt
const projectsCards = document.querySelectorAll('.projects-preview__item')
document.addEventListener('scroll', (e) => {
this.stickyProjectCard(projectsCards, e)
})
stickyProjectCard (cards, e) {
for (const $card of cards) {
const card = $card.getBoundingClientRect()
const height = card.height
const scroll = this.getWindowScroll()
const offsetTop = $card.dataset.offset || (scroll + card.top)
$card.dataset.offset = offsetTop
if (card.top <= 0) {
let scale = 1 - Math.abs((scroll - offsetTop)/(card.height*6))
scale = Math.max(scale, 0)
$card.querySelector('.item-wrapper').style.transform = `scale(${scale}) translateZ(0)`
} else {
$card.querySelector('.item-wrapper').style.transform = ``
}
}
},
Answer the question
In order to leave comments, you need to log in
In short, it is unlikely that anyone will encounter the same problem, but I found a solution - in safari, the value of card.top at some point for some reason became greater than 0, so I set card.top <= 50 in the condition and the bug went away .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question