|
169 | 169 | this.boxOffsetLeft = this.$element.offset().left;
|
170 | 170 | this.boxOffsetBottom = this.boxOffsetTop + this.boxHeight;
|
171 | 171 |
|
172 |
| - var margin = 0; |
173 | 172 | 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; |
175 | 178 |
|
176 | 179 | if (imageHeightMin * this.aspectRatio >= this.boxWidth) {
|
177 | 180 | this.imageWidth = imageHeightMin * this.aspectRatio | 0;
|
178 | 181 | this.imageHeight = imageHeightMin;
|
179 |
| - this.offsetBaseTop = 0; |
| 182 | + this.offsetBaseTop = imageOffsetMin; |
180 | 183 |
|
181 |
| - margin = this.imageWidth - this.boxWidth; |
| 184 | + var margin = this.imageWidth - this.boxWidth; |
182 | 185 |
|
183 | 186 | if (this.positionX == 'left') {
|
184 | 187 | this.offsetLeft = 0;
|
|
194 | 197 | this.imageHeight = this.boxWidth / this.aspectRatio | 0;
|
195 | 198 | this.offsetLeft = 0;
|
196 | 199 |
|
197 |
| - margin = this.imageHeight - imageHeightMin; |
| 200 | + var margin = this.imageHeight - imageHeightMin; |
198 | 201 |
|
199 | 202 | if (this.positionY == 'top') {
|
200 |
| - this.offsetBaseTop = 0; |
| 203 | + this.offsetBaseTop = imageOffsetMin; |
201 | 204 | } else if (this.positionY == 'bottom') {
|
202 |
| - this.offsetBaseTop = - margin; |
| 205 | + this.offsetBaseTop = imageOffsetMin - margin; |
203 | 206 | } else if (!isNaN(this.positionY)) {
|
204 |
| - this.offsetBaseTop = Math.max(this.positionY, - margin); |
| 207 | + this.offsetBaseTop = imageOffsetMin + Math.max(this.positionY, - margin); |
205 | 208 | } else {
|
206 |
| - this.offsetBaseTop = - margin / 2 | 0; |
| 209 | + this.offsetBaseTop = imageOffsetMin - margin / 2 | 0; |
207 | 210 | }
|
208 | 211 | }
|
209 | 212 | },
|
|
0 commit comments