-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fbgrigolo/refazer-FA-scrolAnimacao
Refazer fa scrol animacao
- Loading branch information
Showing
4 changed files
with
53 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.