Skip to content

Instantly share code, notes, and snippets.

@rnaffer
Created June 27, 2016 16:20
Show Gist options
  • Save rnaffer/cdb46aa3925ef76c46078d3bcd548eb9 to your computer and use it in GitHub Desktop.
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.
<span scroll-position="scroll"></span>
<div ng-class="{show: scroll > 400, hide: scroll <= 400}">
<h2>I'm here</h2>
</div>
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