|
59 | 59 | scalarX: 10.0,
|
60 | 60 | scalarY: 10.0,
|
61 | 61 | frictionX: 0.1,
|
62 |
| - frictionY: 0.1 |
| 62 | + frictionY: 0.1, |
| 63 | + originX: 0.5, |
| 64 | + originY: 0.5 |
63 | 65 | };
|
64 | 66 |
|
65 | 67 | function Parallax(element, options) {
|
|
164 | 166 | }
|
165 | 167 | };
|
166 | 168 |
|
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 |
| - |
184 | 169 | Parallax.prototype.camelCase = function(value) {
|
185 | 170 | return value.replace(/-+(.)?/g, function(match, character){
|
186 | 171 | return character ? character.toUpperCase() : '';
|
|
213 | 198 | break;
|
214 | 199 | case '3D':
|
215 | 200 | if (propertySupport) {
|
216 |
| - document.body.appendChild(element); |
| 201 | + var body = document.body || document.createElement('body'); |
| 202 | + body.appendChild(element); |
217 | 203 | element.style[jsProperty] = 'translate3d(1px,1px,1px)';
|
218 | 204 | propertyValue = window.getComputedStyle(element).getPropertyValue(cssProperty);
|
219 | 205 | featureSupport = propertyValue !== undefined && propertyValue.length > 0 && propertyValue !== "none";
|
220 |
| - document.body.removeChild(element); |
| 206 | + body.removeChild(element); |
221 | 207 | }
|
222 | 208 | break;
|
223 | 209 | }
|
|
270 | 256 | Parallax.prototype.updateDimensions = function() {
|
271 | 257 | this.ww = window.innerWidth;
|
272 | 258 | 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; |
275 | 261 | };
|
276 | 262 |
|
277 | 263 | Parallax.prototype.queueCalibration = function(delay) {
|
|
459 | 445 | // Calculate Mouse Input
|
460 | 446 | if (!this.orientationSupport && this.relativeInput) {
|
461 | 447 |
|
462 |
| - // Calculate input relative to the element. |
| 448 | + // Extract element bounds. |
463 | 449 | this.bounds = this.element.getBoundingClientRect();
|
464 | 450 | this.ex = this.bounds.left;
|
465 | 451 | this.ey = this.bounds.top;
|
466 | 452 | this.ew = this.bounds.width;
|
467 | 453 | 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. |
470 | 458 | this.ix = (event.clientX - this.ex - this.ecx) / this.ecx;
|
471 | 459 | this.iy = (event.clientY - this.ey - this.ecy) / this.ecy;
|
472 | 460 |
|
|
0 commit comments