Skip to content

Unbind events #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
};
}]);