Created
June 27, 2016 16:20
-
-
Save rnaffer/cdb46aa3925ef76c46078d3bcd548eb9 to your computer and use it in GitHub Desktop.
Scroll Position Directiva e implementación - Se usa una marca para medir la distancia del scroll y realizar una accn.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span scroll-position="scroll"></span> | |
<div ng-class="{show: scroll > 400, hide: scroll <= 400}"> | |
<h2>I'm here</h2> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive('scrollPosition', function($window) { | |
return { | |
scope: { | |
scroll: '=scrollPosition' | |
}, | |
link: function(scope, element, attrs) { | |
var windowEl = angular.element($window); | |
var handler = function() { | |
scope.scroll = windowEl.scrollTop(); | |
}; | |
windowEl.on('scroll', scope.$apply.bind(scope, handler)); | |
handler(); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment