Skip to content

Commit b0349e3

Browse files
committed
alter calculations for parallax images which are close to the top or bottom of the document
closes #16
1 parent 601068c commit b0349e3

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

parallax.js

100644100755
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,19 @@
169169
this.boxOffsetLeft = this.$element.offset().left;
170170
this.boxOffsetBottom = this.boxOffsetTop + this.boxHeight;
171171

172-
var margin = 0;
173172
var winHeight = Parallax.winHeight;
174-
var imageHeightMin = winHeight - (winHeight - this.boxHeight) * this.speed | 0;
173+
var docHeight = Parallax.docHeight;
174+
var maxOffset = Math.min(this.boxOffsetTop, docHeight - winHeight);
175+
var minOffset = Math.max(this.boxOffsetTop + this.boxHeight - winHeight, 0);
176+
var imageHeightMin = this.boxHeight + (maxOffset - minOffset) * (1 - this.speed) | 0;
177+
var imageOffsetMin = (this.boxOffsetTop - maxOffset) * (1 - this.speed) | 0;
175178

176179
if (imageHeightMin * this.aspectRatio >= this.boxWidth) {
177180
this.imageWidth = imageHeightMin * this.aspectRatio | 0;
178181
this.imageHeight = imageHeightMin;
179-
this.offsetBaseTop = 0;
182+
this.offsetBaseTop = imageOffsetMin;
180183

181-
margin = this.imageWidth - this.boxWidth;
184+
var margin = this.imageWidth - this.boxWidth;
182185

183186
if (this.positionX == 'left') {
184187
this.offsetLeft = 0;
@@ -194,16 +197,16 @@
194197
this.imageHeight = this.boxWidth / this.aspectRatio | 0;
195198
this.offsetLeft = 0;
196199

197-
margin = this.imageHeight - imageHeightMin;
200+
var margin = this.imageHeight - imageHeightMin;
198201

199202
if (this.positionY == 'top') {
200-
this.offsetBaseTop = 0;
203+
this.offsetBaseTop = imageOffsetMin;
201204
} else if (this.positionY == 'bottom') {
202-
this.offsetBaseTop = - margin;
205+
this.offsetBaseTop = imageOffsetMin - margin;
203206
} else if (!isNaN(this.positionY)) {
204-
this.offsetBaseTop = Math.max(this.positionY, - margin);
207+
this.offsetBaseTop = imageOffsetMin + Math.max(this.positionY, - margin);
205208
} else {
206-
this.offsetBaseTop = - margin / 2 | 0;
209+
this.offsetBaseTop = imageOffsetMin - margin / 2 | 0;
207210
}
208211
}
209212
},

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.

0 commit comments

Comments
 (0)