Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
46 changes: 41 additions & 5 deletions scripts/angular-parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('angular-parallax', [
scope: {
parallaxRatio: '@',
parallaxVerticalOffset: '@',
parallaxHorizontalOffset: '@',
parallaxHorizontalOffset: '@'
},
link: function($scope, elem, $attrs) {
var setPosition = function () {
Expand All @@ -23,8 +23,25 @@ angular.module('angular-parallax', [

setPosition();

angular.element($window).bind("scroll", setPosition);
angular.element($window).bind("touchmove", setPosition);
// Handle events
var bind = function() {
angular.element($window).bind("scroll", setPosition);
angular.element($window).bind("touchmove", setPosition);
};
var unbind = function() {
angular.element($window).unbind("scroll", setPosition);
angular.element($window).unbind("touchmove", setPosition);
};
$scope.$on('$destroy', function() {
unbind();
});
attrs.$observe('parallax', function(val) {
if (val) {
bind()
} else {
unbind();
}
})
} // link function
};
}]).directive('parallaxBackground', ['$window', function($window) {
Expand All @@ -48,8 +65,27 @@ angular.module('angular-parallax', [
$scope.$apply();
});

angular.element($window).bind("scroll", setPosition);
angular.element($window).bind("touchmove", setPosition);
// Handle events
var bind = function() {
angular.element($window).bind("scroll", setPosition);
angular.element($window).bind("touchmove", setPosition);
};

// Unbind events on
var unbind = function() {
angular.element($window).unbind("scroll", setPosition);
angular.element($window).unbind("touchmove", setPosition);
}
$scope.$on('$destroy', function() {
unbind();
});
attrs.$observe('parallaxBackground', function(val) {
if (val) {
bind();
} else {
unbind();
}
})
} // link function
};
}]);