Skip to content

Here is a directive I came up with to help with keeping track of page scroll position and when scrolling has started and stopped

Notifications You must be signed in to change notification settings

d1820/angular-scroll-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Angular Scroll Tracker

Here is a directive I came up with to help with keeping track of page scroll position and when scrolling has started and stopped. I had a need for this in trying to hide page content while the user was scrolling up/down a page, and then re-showing the content once the scrolling had stopped. Currently this is only setup up to work at the document level, but and easy modification could be made to allow a new property to drive what scroll area is being monitored. I hope this helps others in case they need a way to tell if page scrolling has started or stopped.

How to Implement

HTML

Simply add the directive to the page or element you want to monitor scrolling on. Next add the scroll-callback function you want to be called from directive when scrolling starts and stops Next set the scroll-page to true for tracking document scrollbar, else can leave out for element scroll tracking

<div scroll-watcher scroll-callback="cntl.scrollStop($event, isEndEvent, isScrollingEvent)" scroll-page"true" >

Callback Function

Note: sample code is in ES6 format. This is an excerpt from a angular controller

 //$event is the standard scroll event from the browser. This contains the X,Y information

 //isEndEvent signals when scrolling has stopped

 //isScrollingEvent signals when scrolling has started

 scrollStop($event, isEndEvent, isScrollingEvent) {

    if (isEndEvent) {

      this.showBottomBar = true;

      return;

    }

    if(isScrollingEvent)

    {

      this.showBottomBar = false;

      return;

    }

  }

About

Here is a directive I came up with to help with keeping track of page scroll position and when scrolling has started and stopped

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published