Skip to content

Instantly share code, notes, and snippets.

@bq1990
Created June 24, 2015 19:09
Show Gist options
  • Save bq1990/724570d866a7e3b30bfc to your computer and use it in GitHub Desktop.
Save bq1990/724570d866a7e3b30bfc to your computer and use it in GitHub Desktop.
overflowY
angular.module('myModule', []).controller('ctrl', function($scope) {
}).directive('overflowY', ['$window', '$document', function($window, $document) {
return {
link: function(scope, element, attrs) {
var w = angular.element($window);
var raw = element[0];
var atBottom = false,
$e = $(element),
inner = $e.find('.wrapper');
var calculateHeight = function() {
var scroll = $document[0].body.scrollTop,
eleTop = raw.offsetTop,
windowHeight = w[0].innerHeight;
if (/*!atBottom && */scroll > (eleTop - windowHeight) && (scroll < eleTop)) {
console.log('sadf', windowHeight - (eleTop - scroll));
$e.css('height', windowHeight - (eleTop - scroll));
//} else if (atBottom) {
//do nothing
//} else {
//scroll past the div
//
// element.css('height', windowHeight);
}
};
calculateHeight();
w.bind('resize', calculateHeight);
/*
element.bind('scroll', function() {
if ($e.height() + raw.scrollTop >= inner.height()) {
atBottom = true;
console.log('at bot');
} else {
atBottom = false;
console.log('not at bot');
}
});
*/
element.css('overflow-y', 'scroll');
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment