Skip to content

Instantly share code, notes, and snippets.

@engmagdy87
Created August 5, 2020 11:59
Show Gist options
  • Select an option

  • Save engmagdy87/77ba725112765866d09a089b8103b3be to your computer and use it in GitHub Desktop.

Select an option

Save engmagdy87/77ba725112765866d09a089b8103b3be to your computer and use it in GitHub Desktop.
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