Skip to content

Instantly share code, notes, and snippets.

@stevermeister stevermeister/ngSticky.js
Last active Aug 29, 2015

Embed
What would you like to do?
angular.module('ui')
.directive('ngSticky', function($window) {
return function($scope, element) {
var start,
$win = element($window);
$win.on('scroll', function() {
var scroll = $win.scrollTop();
start = start || element.offset().top;
if (scroll > start) {
element.addClass('stuck');
} else {
element.removeClass('stuck');
}
});
$win.on('resize', function recheckPositions() {
element.width( element.parent().width() );
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.