I am trying to recreate this script: http://jsfiddle.net/mariusc23/s6mLJ/31/ using AngularJS.
Effectively, when the user scrolls down the page, header
disappears. If at any moment the user scrolls, even 1 / 2px ... header
crashes.
I created a plunker: http://plnkr.co/edit/DBiY57kKUWiISVDJiDU4?p=preview , which seems to have applied the class hide-header
, but it looks like I can't appear on scrollUp.
Directive
app.directive("myDirective", function ($window) {
return function(scope, element, attrs) {
angular.element($window).bind("scroll", function() {
var lastScrollTop = 0;
var delta = 50;
var windowInnerHeight = $window.innerHeight;
var windowHeight = $window.height;
var st = this.pageYOffset;
if(Math.abs(lastScrollTop - st) <= delta)
return;
if (st > lastScrollTop && st > 50){
console.log("in if...");
scope.navUp = true;
} else {
if(st + windowInnerHeight < windowHeight) {
console.log("in else...");
}
}
lastScrollTop = st;
scope.$apply();
});
};
});
HTML:
<body ng-controller="MainCtrl">
<header my-directive ng-class="{true : 'hide-header'}[navUp]">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</header>
</body>
source
share