Skip to content

Instantly share code, notes, and snippets.

@stevermeister
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevermeister/ec4c7da12deaf8e86469 to your computer and use it in GitHub Desktop.
Save stevermeister/ec4c7da12deaf8e86469 to your computer and use it in GitHub Desktop.
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