Skip to content

Instantly share code, notes, and snippets.

@luke-rmaki
Last active October 5, 2018 10:17
Show Gist options
  • Select an option

  • Save luke-rmaki/1149b3d2496f7c34da80b7ee9bd7a368 to your computer and use it in GitHub Desktop.

Select an option

Save luke-rmaki/1149b3d2496f7c34da80b7ee9bd7a368 to your computer and use it in GitHub Desktop.

Revisions

  1. Luke revised this gist Oct 5, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion script.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function smoothScroll(target) {
    function elementInView(target) {
    // selects target div
    const targetDiv = document.querySelector(target);

  2. Luke created this gist Oct 5, 2018.
    23 changes: 23 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    function smoothScroll(target) {
    // selects target div
    const targetDiv = document.querySelector(target);

    // gets target position from top of viewport
    const targetPosition = targetDiv.getBoundingClientRect();

    switch (true) {
    case targetPosition.top > 1:
    console.log('hidden');
    break;
    case targetPosition.top <= 0 && targetPosition.bottom >= 0:
    console.log('visible');
    break;
    case targetPosition.bottom < 0:
    console.log('hidden');
    break;
    default:
    break;
    }
    }

    // add function to document.addEventListener('scroll')