app.directive('scroll', ['$window','$timeout',function($window,$timeout) { return { restrict: 'A', scope: { offset: '@', offsetSecond: '@', scrollClass: '@', scrollClassSecond: '@', scrollClassThird: '@', isOnce: '=' }, link: function(scope, element) { var canIHover = function(){ element.removeClass(scope.scrollClassThird); $timeout(function(){ element.addClass(scope.scrollClassThird); },1000) } var windowJQ = angular.element($window) windowJQ.bind("scroll", function() { if (window.pageYOffset >= parseInt(scope.offset)){ if(scope.isOnce){ $timeout(function(){ var circleFrontArr = document.querySelectorAll('.loyalty-programs-item-circle-back'); for (var i = 0; i < circleFrontArr.length; i++) { circleFrontArr[i].style.opacity = '0'; } },300) } canIHover(); element.addClass(scope.scrollClass); } else { if(!scope.isOnce){ canIHover(); element.removeClass(scope.scrollClass); } } if(window.pageYOffset >= parseInt(scope.offsetSecond)){ element.addClass(scope.scrollClassSecond); canIHover(); } else { element.removeClass(scope.scrollClassSecond); canIHover(); } }); } }; }])