Skip to content

Parallax background center #14

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 7 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
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-parallax",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "https://github.com/brettdonohoo/angular-parallax",
"authors": [
"Brett Donohoo <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div ng-controller="ParallaxExampleCtrl">
<h1 parallax parallax-ratio="1.22" parallax-vertical-offset="10" parallax-horizontal-offset="600" style="position:absolute;">Angular Parallax</h1>
<div parallax-background class="photo nature" parallax-ratio="0.5"><span style="font-size:1em;">Nature</span></div>
<div parallax-background class="photo food" parallax-ratio="0.8"><span style="font-size:4em;">Food</span></div>
<div parallax-background class="photo food" parallax-background-position="center" parallax-ratio="0.8"><span style="font-size:4em;">Food</span></div>
<div parallax-background class="photo animals" parallax-ratio="0.7">Animals</div>
<div parallax-background class="photo cats" parallax-ratio="1">Cats</div>
<img parallax parallax-ratio="1.88" parallax-vertical-offset="100" parallax-horizontal-offset="40" style="position:absolute;" src="images/muther.jpg" />
Expand Down
5 changes: 5 additions & 0 deletions scripts/angular-parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ angular.module('angular-parallax', [
template: '<div ng-transclude></div>',
scope: {
parallaxRatio: '@',
parallaxBackgroundPosition: '@'
},
link: function($scope, elem, attrs) {
var setPosition = function () {
var calcValY = (elem.prop('offsetTop') - $window.pageYOffset) * ($scope.parallaxRatio ? $scope.parallaxRatio : 1.1 );
if($scope.parallaxPosition === 'center') {
calcValY -= elem[0].offsetHeight / 2;
}

// horizontal positioning
elem.css('background-position', "50% " + calcValY + "px");
};
Expand Down