Skip to content

Commit 11c7fb9

Browse files
committed
🇬🇧 Refactored out layer parsing to updateLayers method.
1 parent 1f20cd7 commit 11c7fb9

9 files changed

+76
-32
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var scene = document.getElementById('scene');
123123
var parallax = new Parallax(scene);
124124
parallax.enable();
125125
parallax.disable();
126+
parallax.updateLayers(); // Useful for reparsing the layers in your scene if you change their data-depth value
126127
parallax.calibrate(false, true);
127128
parallax.invert(false, true);
128129
parallax.limit(false, 10);
@@ -164,6 +165,7 @@ $('#scene').parallax({
164165
var $scene = $('#scene').parallax();
165166
$scene.parallax('enable');
166167
$scene.parallax('disable');
168+
$scene.parallax('updateLayers');
167169
$scene.parallax('calibrate', false, true);
168170
$scene.parallax('invert', false, true);
169171
$scene.parallax('limit', false, 10);

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parallax",
33
"description": "Parallax Engine that reacts to the orientation of a smart device.",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"license": "MIT",
66
"homepage": "http://wagerfield.github.io/parallax/",
77
"authors": [

deploy/jquery.parallax.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,24 @@
218218
position:'relative'
219219
});
220220
}
221+
222+
// Hardware Accelerate Context
223+
this.accelerate(this.$context);
224+
225+
// Setup
226+
this.updateLayers();
227+
this.updateDimensions();
228+
this.enable();
229+
this.queueCalibration(this.calibrationDelay);
230+
};
231+
232+
Plugin.prototype.updateLayers = function() {
233+
234+
// Cache Layer Elements
235+
this.$layers = this.$context.find('.layer');
236+
this.depths = [];
237+
238+
// Configure Layer Styles
221239
this.$layers.css({
222240
position:'absolute',
223241
display:'block',
@@ -228,19 +246,13 @@
228246
position:'relative'
229247
});
230248

249+
// Hardware Accelerate Layers
250+
this.accelerate(this.$layers);
251+
231252
// Cache Depths
232253
this.$layers.each($.proxy(function(index, element) {
233254
this.depths.push($(element).data('depth') || 0);
234255
}, this));
235-
236-
// Hardware Accelerate Elements
237-
this.accelerate(this.$context);
238-
this.accelerate(this.$layers);
239-
240-
// Setup
241-
this.updateDimensions();
242-
this.enable();
243-
this.queueCalibration(this.calibrationDelay);
244256
};
245257

246258
Plugin.prototype.updateDimensions = function() {
@@ -490,6 +502,7 @@
490502
var API = {
491503
enable: Plugin.prototype.enable,
492504
disable: Plugin.prototype.disable,
505+
updateLayers: Plugin.prototype.updateLayers,
493506
calibrate: Plugin.prototype.calibrate,
494507
friction: Plugin.prototype.friction,
495508
invert: Plugin.prototype.invert,

deploy/jquery.parallax.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/parallax.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@
252252
this.element.style.position = 'relative';
253253
}
254254

255+
// Setup
256+
this.updateLayers();
257+
this.updateDimensions();
258+
this.enable();
259+
this.queueCalibration(this.calibrationDelay);
260+
};
261+
262+
Parallax.prototype.updateLayers = function() {
263+
264+
// Cache Layer Elements
265+
this.layers = this.element.getElementsByClassName('layer');
266+
this.depths = [];
267+
255268
// Configure Layer Styles
256269
for (var i = 0, l = this.layers.length; i < l; i++) {
257270
var layer = this.layers[i];
@@ -264,11 +277,6 @@
264277
// Cache Layer Depth
265278
this.depths.push(this.data(layer, 'depth') || 0);
266279
}
267-
268-
// Setup
269-
this.updateDimensions();
270-
this.enable();
271-
this.queueCalibration(this.calibrationDelay);
272280
};
273281

274282
Parallax.prototype.updateDimensions = function() {

deploy/parallax.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parallax",
33
"description": "Parallax Engine that reacts to the orientation of a smart device.",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"license": "MIT",
66
"homepage": "http://wagerfield.github.io/parallax/",
77
"author": "Matthew Wagerfield <[email protected]>",

source/jquery.parallax.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@
187187
position:'relative'
188188
});
189189
}
190+
191+
// Hardware Accelerate Context
192+
this.accelerate(this.$context);
193+
194+
// Setup
195+
this.updateLayers();
196+
this.updateDimensions();
197+
this.enable();
198+
this.queueCalibration(this.calibrationDelay);
199+
};
200+
201+
Plugin.prototype.updateLayers = function() {
202+
203+
// Cache Layer Elements
204+
this.$layers = this.$context.find('.layer');
205+
this.depths = [];
206+
207+
// Configure Layer Styles
190208
this.$layers.css({
191209
position:'absolute',
192210
display:'block',
@@ -197,19 +215,13 @@
197215
position:'relative'
198216
});
199217

218+
// Hardware Accelerate Layers
219+
this.accelerate(this.$layers);
220+
200221
// Cache Depths
201222
this.$layers.each($.proxy(function(index, element) {
202223
this.depths.push($(element).data('depth') || 0);
203224
}, this));
204-
205-
// Hardware Accelerate Elements
206-
this.accelerate(this.$context);
207-
this.accelerate(this.$layers);
208-
209-
// Setup
210-
this.updateDimensions();
211-
this.enable();
212-
this.queueCalibration(this.calibrationDelay);
213225
};
214226

215227
Plugin.prototype.updateDimensions = function() {
@@ -459,6 +471,7 @@
459471
var API = {
460472
enable: Plugin.prototype.enable,
461473
disable: Plugin.prototype.disable,
474+
updateLayers: Plugin.prototype.updateLayers,
462475
calibrate: Plugin.prototype.calibrate,
463476
friction: Plugin.prototype.friction,
464477
invert: Plugin.prototype.invert,

source/parallax.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@
221221
this.element.style.position = 'relative';
222222
}
223223

224+
// Setup
225+
this.updateLayers();
226+
this.updateDimensions();
227+
this.enable();
228+
this.queueCalibration(this.calibrationDelay);
229+
};
230+
231+
Parallax.prototype.updateLayers = function() {
232+
233+
// Cache Layer Elements
234+
this.layers = this.element.getElementsByClassName('layer');
235+
this.depths = [];
236+
224237
// Configure Layer Styles
225238
for (var i = 0, l = this.layers.length; i < l; i++) {
226239
var layer = this.layers[i];
@@ -233,11 +246,6 @@
233246
// Cache Layer Depth
234247
this.depths.push(this.data(layer, 'depth') || 0);
235248
}
236-
237-
// Setup
238-
this.updateDimensions();
239-
this.enable();
240-
this.queueCalibration(this.calibrationDelay);
241249
};
242250

243251
Parallax.prototype.updateDimensions = function() {

0 commit comments

Comments
 (0)