1
Window.innerheight does not work in Safari browser.
When I scroll on the page and the element arrives at a particular page location it adds a class in HTML, in all other browser that code works. However in Safari I was unable to make the elements do not receive the class specified within the code. I believe the problem is in this window.innerheight, I need a help to solve this problem.
(function(){
//Declarando as variáveis
var target = document.querySelectorAll('.border-bottom');
var classAnimacao = 'animacao-border-bottom';
var offset = window.innerHeight * 3/4; //Calculo da tamanho da tela para animação começar
var animes = document.querySelectorAll('[data-anime]');
//Função scrollTop
function scrollTop() {
//Distancia do topo da tela
var documentTop = document.documentElement.scrollTop;
// Alvo (border-bottom)
target.forEach(function(element){
var itemTop = element.offsetTop;
if (documentTop > itemTop - offset) {
element.classList.add(classAnimacao);
} else {
element.classList.remove(classAnimacao);
}
});
animes.forEach(function(element){
var anime = element.offsetTop;
if(documentTop > anime - offset) {
element.classList.add('animation');
} else {
element.classList.remove('animation');
}
});
}
// Adiciona uma vez quando atualizada a página
scrollTop();
// Ativando função no rolar do scroll (rolar da página)
document.addEventListener('scroll', debounce(function(){
scrollTop();
}, 200));
}());
I believe that the problem is not in innerheight. Safari does not recognize the code
document.documentElement.scrollTop
. To get the scroll in Safari usewindow.pageYOffset
. So you can use both:var documentTop = document.documentElement.scrollTop || window.pageYOffset;
that will work in Safari and other browsers.– Sam
Thank you very much! You do not know how helped me and a lot, I was looking for the error and did not think. I even thought it was a mistake in foreach too. But I managed to solve vlw.
– Fernando Estevam
Blz. I’ll post an ok reply.
– Sam