The window.innerHeight does not work in the Safari browser.
When I scroll on the page and the element arrives at a certain place on the page, it adds a class to HTML, in all other browsers that code works. However in Safari I could not make the elements do not get the specified class inside the code. I believe the problem is in this window.innerHeight, I need some 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));
}());