Last active
August 29, 2015 14:02
-
-
Save stevermeister/ec4c7da12deaf8e86469 to your computer and use it in GitHub Desktop.
This file contains 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
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