Created
August 5, 2020 11:59
-
-
Save engmagdy87/77ba725112765866d09a089b8103b3be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { HEADER_HEIGHT, HEADER_HEIGHT_MOBILE } from "../constants/Header" | |
| import isDeviceSmart from "../helpers/DetectIsDeviceSmart" | |
| const whatIsTheSectionAppearInViewport = () => { | |
| let fromTop = document.getElementById("app").scrollTop; | |
| const ids = document.getElementsByClassName("wrapper"); | |
| let offsetFromTop = isDeviceSmart() ? HEADER_HEIGHT_MOBILE : HEADER_HEIGHT | |
| let currentActiveItem = "" | |
| for (let i = 0; i < ids.length; i++) { | |
| const id = ids[i].id; | |
| const section = document.getElementById(id); | |
| if ( | |
| section.offsetTop <= fromTop + offsetFromTop && | |
| section.offsetTop + section.scrollHeight > fromTop | |
| ) currentActiveItem = section.id | |
| } | |
| return currentActiveItem | |
| } | |
| export default whatIsTheSectionAppearInViewport |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment