Skip to content

wowissu/angular-scroll-watch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

angular-scroll-watch

Basic use

    var app = angular.module('app', ['scrollWatch']);
    // ...
    app.controller('appCtrl', ['$scope', 'ScrollWatch', function ($scope, ScrollWatch) {
        var myWatch = new ScrollWatch();
            //default scrollElement is window
            //default scope is $rootScope

        // also define it by yourself
        var myWatch = new ScrollWatch('#scrollElement', $scope);
    };

Define watch point

addPoint (pointName, integer || callback, watchScrollBottom = false)
myWatch.addPoint('myPoint', 500);

$scope.$$point.myPoint // find point in $$point , it will be boolean
  • If third argument is true,then check point on scroll bottom
    myWatch.addPoint('myBottomPoint', 500, true);
  • Also use callback
    myWatch.addPoint('myPoint', function (scroll) {
        return scroll.top > 500;
    });

Watch defined point

watchPoint (pointName, callback)
    myWatch.watchPoint('topPoint', function (val) {
        console.log('watch topPoint status: ', val);
    });

HTML

Watch scroll top or bottom

  • When scrollTop > 500px , hide element.
  • When scrollBottom < 500px , show target element.
    <body ng-app="app" ng-controller="appCtrl">
        ...
        <div ng-hide="$$scrollTop > 500" >hide me when scroll top over 500px</div>
        <div ng-show="$$scrollBottom > 500" >show me when scroll bottom over 500px</div>
        ...
    </body>

Watch Element

  • When scrollTop over myPoint1 element, $$point.myPoint1 = true.
  • When scrollBottom over myPoint2 element, $$point.myPoint2 = true.
    <body ng-app="app" ng-controller="appCtrl">
        ...
        <div scroll-point="myPoint1" ng-class="{top_over_me: $$point.myPoint1}"></div>
        <div scroll-point="myPoint2" bottom ng-class="{bottom_over_me: $$point.myPoint2}"></div>
        ...
    </body>

Scroll up or down

    <div ng-show="$$scrollUp">show me on scroll up</div>
    <div ng-show="$$scrollDown">show me on scroll down</div>

About

watch scroll by angular

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published