Skip to content

Commit

Permalink
🇬🇧 Resolved #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
wagerfield committed Apr 21, 2014
1 parent 634fcb3 commit 05d85d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 51 deletions.
38 changes: 13 additions & 25 deletions deploy/parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
scalarX: 10.0,
scalarY: 10.0,
frictionX: 0.1,
frictionY: 0.1
frictionY: 0.1,
originX: 0.5,
originY: 0.5
};

function Parallax(element, options) {
Expand Down Expand Up @@ -164,23 +166,6 @@
}
};

Parallax.prototype.offset = function(element) {
var x = 0, y = 0, scrollLeft, scrollTop;
while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
if (element === document.body) {
scrollLeft = document.documentElement.scrollLeft;
scrollTop = document.documentElement.scrollTop;
} else {
scrollLeft = element.scrollLeft;
scrollTop = element.scrollTop;
}
x += element.offsetLeft - scrollLeft;
y += element.offsetTop - scrollTop;
element = element.offsetParent;
}
return {top:y, left:x};
};

Parallax.prototype.camelCase = function(value) {
return value.replace(/-+(.)?/g, function(match, character){
return character ? character.toUpperCase() : '';
Expand Down Expand Up @@ -213,11 +198,12 @@
break;
case '3D':
if (propertySupport) {
document.body.appendChild(element);
var body = document.body || document.createElement('body');
body.appendChild(element);
element.style[jsProperty] = 'translate3d(1px,1px,1px)';
propertyValue = window.getComputedStyle(element).getPropertyValue(cssProperty);
featureSupport = propertyValue !== undefined && propertyValue.length > 0 && propertyValue !== "none";
document.body.removeChild(element);
body.removeChild(element);
}
break;
}
Expand Down Expand Up @@ -270,8 +256,8 @@
Parallax.prototype.updateDimensions = function() {
this.ww = window.innerWidth;
this.wh = window.innerHeight;
this.wcx = this.ww / 2;
this.wcy = this.wh / 2;
this.wcx = this.ww * this.originX;
this.wcy = this.wh * this.originY;
};

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

// Calculate input relative to the element.
// Extract element bounds.
this.bounds = this.element.getBoundingClientRect();
this.ex = this.bounds.left;
this.ey = this.bounds.top;
this.ew = this.bounds.width;
this.eh = this.bounds.height;
this.ecx = this.ew / 2;
this.ecy = this.eh / 2;
this.ecx = this.ew * this.originX;
this.ecy = this.eh * this.originY;

// Calculate input relative to the element.
this.ix = (event.clientX - this.ex - this.ecx) / this.ecx;
this.iy = (event.clientY - this.ey - this.ecy) / this.ecy;

Expand Down
2 changes: 1 addition & 1 deletion deploy/parallax.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 05d85d4

Please sign in to comment.