scroll.js 1.5 KB

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