scroll.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. isOnce: '='
  11. },
  12. link: function(scope, element) {
  13. var canIHover = function(){
  14. element.removeClass(scope.scrollClassThird);
  15. $timeout(function(){
  16. element.addClass(scope.scrollClassThird);
  17. },1000)
  18. }
  19. var windowJQ = angular.element($window)
  20. windowJQ.bind("scroll", function() {
  21. if (window.pageYOffset >= parseInt(scope.offset)){
  22. if(scope.isOnce){
  23. $timeout(function(){
  24. var circleFrontArr = document.querySelectorAll('.loyalty-programs-item-circle-back');
  25. for (var i = 0; i < circleFrontArr.length; i++) {
  26. circleFrontArr[i].style.opacity = '0';
  27. }
  28. },300)
  29. }
  30. canIHover();
  31. element.addClass(scope.scrollClass);
  32. } else {
  33. if(!scope.isOnce){
  34. canIHover();
  35. element.removeClass(scope.scrollClass);
  36. }
  37. }
  38. if(window.pageYOffset >= parseInt(scope.offsetSecond)){
  39. element.addClass(scope.scrollClassSecond);
  40. canIHover();
  41. } else {
  42. element.removeClass(scope.scrollClassSecond);
  43. canIHover();
  44. }
  45. });
  46. }
  47. };
  48. }])