Skip to content

Commit

Permalink
Merge pull request #9 from fbgrigolo/refazer-FA-scrolAnimacao
Browse files Browse the repository at this point in the history
Refazer fa scrol animacao
  • Loading branch information
sc0tf1eld authored Aug 30, 2022
2 parents 75dc8bf + f279e32 commit bebdebf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
6 changes: 4 additions & 2 deletions FantasticAnimals/js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Modal from './modules/modal.js';
import Tooltip from './modules/tooltip.js';
import fetchAnimais from './modules/fetch-animais.js';
import fetchBitcoin from './modules/fetch-bitcoin.js';
import ScrollAnima from './modules/scroll-anima.js';
import initDropdownMenu from './modules/dropdown-menu.js';
import initMenuMobile from './modules/menu-mobile.js';
import initFuncionamento from './modules/funcionamento.js';
import initAnimacaoScroll from './modules/scroll-animacao.js';

const scrollSuave = new ScrollSuave('[data-js="menu"] a[href^="#"]');
scrollSuave.init();
Expand All @@ -25,10 +25,12 @@ modal.init();
const tooltip = new Tooltip("[data-tooltip]", );
tooltip.init();

const scrollAnima = new ScrollAnima('[data-js="scroll"]');
scrollAnima.init();

initDropdownMenu();
initMenuMobile();
initFuncionamento();
initAnimacaoScroll();

fetchAnimais('./js/animaisapi.json', '.numeros-grid');

Expand Down
48 changes: 48 additions & 0 deletions FantasticAnimals/js/modules/scroll-anima.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Anima as sections durante o scroll da página
export default class ScrollAnima {
constructor(sections) {
this.sections = document.querySelectorAll(sections)
this.windowMetade = window.innerHeight * 0.6;

this.checkDistance = this.checkDistance.bind(this);
}

// Pega a distância de cada item em relação
// ao topo do site
getDistance() {
this.distance = [...this.sections].map((section) => {
const offset = section.offsetTop;
return {
element: section,
offset: Math.floor(offset - this.windowMetade),
};
});
}

// Verifica a distância em cada objeto
// em relacação ao scroll do site
checkDistance() {
this.distance.forEach((item) => {
if (window.pageYOffset > item.offset) {
item.element.classList.add("ativo");
} else if (item.element.classList.contains('ativo')) {
item.element.classList.remove('ativo');
}
});
}

init() {
if (this.sections.length) {
this.getDistance();
this.checkDistance();
window.addEventListener("scroll", this.checkDistance);
}
return this;
}

// Remove o event de scroll
stop() {
window.removeEventListener("scroll", this.checkDistance);
}
}

25 changes: 0 additions & 25 deletions FantasticAnimals/js/modules/scroll-animacao.js

This file was deleted.

2 changes: 1 addition & 1 deletion FantasticAnimals/main.js

Large diffs are not rendered by default.

0 comments on commit bebdebf

Please sign in to comment.