Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refazer fa scrol animacao #9

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.