Skip to content

Commit 05d85d4

Browse files
committed
🇬🇧 Resolved wagerfield#38.
1 parent 634fcb3 commit 05d85d4

File tree

3 files changed

+27
-51
lines changed

3 files changed

+27
-51
lines changed

deploy/parallax.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
scalarX: 10.0,
6060
scalarY: 10.0,
6161
frictionX: 0.1,
62-
frictionY: 0.1
62+
frictionY: 0.1,
63+
originX: 0.5,
64+
originY: 0.5
6365
};
6466

6567
function Parallax(element, options) {
@@ -164,23 +166,6 @@
164166
}
165167
};
166168

167-
Parallax.prototype.offset = function(element) {
168-
var x = 0, y = 0, scrollLeft, scrollTop;
169-
while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
170-
if (element === document.body) {
171-
scrollLeft = document.documentElement.scrollLeft;
172-
scrollTop = document.documentElement.scrollTop;
173-
} else {
174-
scrollLeft = element.scrollLeft;
175-
scrollTop = element.scrollTop;
176-
}
177-
x += element.offsetLeft - scrollLeft;
178-
y += element.offsetTop - scrollTop;
179-
element = element.offsetParent;
180-
}
181-
return {top:y, left:x};
182-
};
183-
184169
Parallax.prototype.camelCase = function(value) {
185170
return value.replace(/-+(.)?/g, function(match, character){
186171
return character ? character.toUpperCase() : '';
@@ -213,11 +198,12 @@
213198
break;
214199
case '3D':
215200
if (propertySupport) {
216-
document.body.appendChild(element);
201+
var body = document.body || document.createElement('body');
202+
body.appendChild(element);
217203
element.style[jsProperty] = 'translate3d(1px,1px,1px)';
218204
propertyValue = window.getComputedStyle(element).getPropertyValue(cssProperty);
219205
featureSupport = propertyValue !== undefined && propertyValue.length > 0 && propertyValue !== "none";
220-
document.body.removeChild(element);
206+
body.removeChild(element);
221207
}
222208
break;
223209
}
@@ -270,8 +256,8 @@
270256
Parallax.prototype.updateDimensions = function() {
271257
this.ww = window.innerWidth;
272258
this.wh = window.innerHeight;
273-
this.wcx = this.ww / 2;
274-
this.wcy = this.wh / 2;
259+
this.wcx = this.ww * this.originX;
260+
this.wcy = this.wh * this.originY;
275261
};
276262

277263
Parallax.prototype.queueCalibration = function(delay) {
@@ -459,14 +445,16 @@
459445
// Calculate Mouse Input
460446
if (!this.orientationSupport && this.relativeInput) {
461447

462-
// Calculate input relative to the element.
448+
// Extract element bounds.
463449
this.bounds = this.element.getBoundingClientRect();
464450
this.ex = this.bounds.left;
465451
this.ey = this.bounds.top;
466452
this.ew = this.bounds.width;
467453
this.eh = this.bounds.height;
468-
this.ecx = this.ew / 2;
469-
this.ecy = this.eh / 2;
454+
this.ecx = this.ew * this.originX;
455+
this.ecy = this.eh * this.originY;
456+
457+
// Calculate input relative to the element.
470458
this.ix = (event.clientX - this.ex - this.ecx) / this.ecx;
471459
this.iy = (event.clientY - this.ey - this.ecy) / this.ecy;
472460

deploy/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)