Skip to content

Commit dac0f86

Browse files
author
David Hutchings
committed
Adding "scroll-target' option (take 2)
1 parent dac87a7 commit dac0f86

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

angular-parallax.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ directive('duParallax',
6464
x : '=',
6565
rotation : '=',
6666
opacity : '=',
67-
custom : '='
67+
custom : '=',
68+
scrollTarget: '@'
6869
},
6970
link: function($scope, $element, $attr){
7071
var element = $element[0];
7172
var currentProperties;
7273
var inited = false;
7374

75+
var scrollTarget = $scope.scrollTarget ? $($scope.scrollTarget) : $document;
76+
7477
var onScroll = function(){
7578
var scrollY = $document.scrollTop();
7679
var rect = element.getBoundingClientRect();
@@ -125,10 +128,10 @@ directive('duParallax',
125128
}
126129
};
127130

128-
$document.on('scroll touchmove', onScroll).triggerHandler('scroll');
131+
scrollTarget.on('scroll touchmove', onScroll).triggerHandler('scroll');
129132

130133
$scope.$on('$destroy', function() {
131-
$document.off('scroll touchmove', onScroll);
134+
scrollTarget.off('scroll touchmove', onScroll);
132135
});
133136
}
134137
};

angular-parallax.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular-parallax.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/parallax.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ directive('duParallax',
4343
x : '=',
4444
rotation : '=',
4545
opacity : '=',
46-
custom : '='
46+
custom : '=',
47+
scrollTarget: '@'
4748
},
4849
link: function($scope, $element, $attr){
4950
var element = $element[0];
5051
var currentProperties;
5152
var inited = false;
5253

54+
var scrollTarget = $scope.scrollTarget ? $($scope.scrollTarget) : $document;
55+
5356
var onScroll = function(){
5457
var scrollY = $document.scrollTop();
5558
var rect = element.getBoundingClientRect();
@@ -104,10 +107,10 @@ directive('duParallax',
104107
}
105108
};
106109

107-
$document.on('scroll touchmove', onScroll).triggerHandler('scroll');
110+
scrollTarget.on('scroll touchmove', onScroll).triggerHandler('scroll');
108111

109112
$scope.$on('$destroy', function() {
110-
$document.off('scroll touchmove', onScroll);
113+
scrollTarget.off('scroll touchmove', onScroll);
111114
});
112115
}
113116
};

0 commit comments

Comments
 (0)