scroll.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. app.directive('scroll', ['$window','$timeout',function($window,$timeout) {
  2. return {
  3. restrict: 'A',
  4. scope: {
  5. offset: '@',
  6. offsetSecond: '@',
  7. scrollClass: '@',
  8. scrollClassSecond: '@',
  9. scrollClassThird: '@'
  10. },
  11. link: function(scope, element) {
  12. var canIHover = function(){
  13. element.removeClass(scope.scrollClassThird);
  14. $timeout(function(){
  15. element.addClass(scope.scrollClassThird);
  16. },1000)
  17. }
  18. var windowJQ = angular.element($window)
  19. windowJQ.bind("scroll", function() {
  20. if (window.pageYOffset >= parseInt(scope.offset)) {
  21. element.addClass(scope.scrollClass);
  22. canIHover();
  23. } else {
  24. element.removeClass(scope.scrollClass);
  25. canIHover();
  26. }
  27. if(window.pageYOffset >= parseInt(scope.offsetSecond)){
  28. element.addClass(scope.scrollClassSecond);
  29. canIHover();
  30. } else {
  31. element.removeClass(scope.scrollClassSecond);
  32. canIHover();
  33. }
  34. });
  35. }
  36. };
  37. }])