Last active
August 29, 2015 14:05
-
-
Save larsmaxwell/3e48f9015a10354d2fbf to your computer and use it in GitHub Desktop.
messing w directives
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
poopoo.directive('fixedHeader', function() { | |
return { | |
// Restrict it to be an attribute in this case | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
window.scrollmything = function() { | |
var window = this; | |
window.elementHeight = element.height(); | |
window.activate(); | |
$(window).on('scroll', this.activate); | |
$(window).on('resize', this.activate); | |
}; | |
window.activate = function() { | |
var scrollTop = $(window).scrollTop(); | |
if( scrollTop > window.elementHeight ) { | |
window.scrollEnabled(); | |
} else { | |
window.scrollDisabled(); | |
} | |
}; | |
window.scrollEnabled = function() { | |
$(element).addClass('fixed'); | |
}; | |
window.scrollDisabled = function() { | |
$(element).removeClass('fixed'); | |
}; | |
window.scrollmything(); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey try using $window instead of window. Then if you ever wanted to test this you could substitute $window to achieve a desired outcome.