12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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)
- }
- element.addClass(scope.scrollClass);
- canIHover();
- } else {
- if(!scope.isOnce){
- element.removeClass(scope.scrollClass);
- canIHover();
- }
- }
- if(window.pageYOffset >= parseInt(scope.offsetSecond)){
- element.addClass(scope.scrollClassSecond);
- canIHover();
- } else {
- element.removeClass(scope.scrollClassSecond);
- canIHover();
- }
- });
- }
- };
- }])
|