Skip to content

Commit

Permalink
🇬🇧 Refactored out layer parsing to updateLayers method.
Browse files Browse the repository at this point in the history
  • Loading branch information
wagerfield committed Apr 26, 2014
1 parent 1f20cd7 commit 11c7fb9
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var scene = document.getElementById('scene');
var parallax = new Parallax(scene);
parallax.enable();
parallax.disable();
parallax.updateLayers(); // Useful for reparsing the layers in your scene if you change their data-depth value
parallax.calibrate(false, true);
parallax.invert(false, true);
parallax.limit(false, 10);
Expand Down Expand Up @@ -164,6 +165,7 @@ $('#scene').parallax({
var $scene = $('#scene').parallax();
$scene.parallax('enable');
$scene.parallax('disable');
$scene.parallax('updateLayers');
$scene.parallax('calibrate', false, true);
$scene.parallax('invert', false, true);
$scene.parallax('limit', false, 10);
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parallax",
"description": "Parallax Engine that reacts to the orientation of a smart device.",
"version": "2.1.1",
"version": "2.1.2",
"license": "MIT",
"homepage": "http://wagerfield.github.io/parallax/",
"authors": [
Expand Down
31 changes: 22 additions & 9 deletions deploy/jquery.parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@
position:'relative'
});
}

// Hardware Accelerate Context
this.accelerate(this.$context);

// Setup
this.updateLayers();
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Plugin.prototype.updateLayers = function() {

// Cache Layer Elements
this.$layers = this.$context.find('.layer');
this.depths = [];

// Configure Layer Styles
this.$layers.css({
position:'absolute',
display:'block',
Expand All @@ -228,19 +246,13 @@
position:'relative'
});

// Hardware Accelerate Layers
this.accelerate(this.$layers);

// Cache Depths
this.$layers.each($.proxy(function(index, element) {
this.depths.push($(element).data('depth') || 0);
}, this));

// Hardware Accelerate Elements
this.accelerate(this.$context);
this.accelerate(this.$layers);

// Setup
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Plugin.prototype.updateDimensions = function() {
Expand Down Expand Up @@ -490,6 +502,7 @@
var API = {
enable: Plugin.prototype.enable,
disable: Plugin.prototype.disable,
updateLayers: Plugin.prototype.updateLayers,
calibrate: Plugin.prototype.calibrate,
friction: Plugin.prototype.friction,
invert: Plugin.prototype.invert,
Expand Down
2 changes: 1 addition & 1 deletion deploy/jquery.parallax.min.js

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions deploy/parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@
this.element.style.position = 'relative';
}

// Setup
this.updateLayers();
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Parallax.prototype.updateLayers = function() {

// Cache Layer Elements
this.layers = this.element.getElementsByClassName('layer');
this.depths = [];

// Configure Layer Styles
for (var i = 0, l = this.layers.length; i < l; i++) {
var layer = this.layers[i];
Expand All @@ -264,11 +277,6 @@
// Cache Layer Depth
this.depths.push(this.data(layer, 'depth') || 0);
}

// Setup
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Parallax.prototype.updateDimensions = function() {
Expand Down
2 changes: 1 addition & 1 deletion deploy/parallax.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parallax",
"description": "Parallax Engine that reacts to the orientation of a smart device.",
"version": "2.1.1",
"version": "2.1.2",
"license": "MIT",
"homepage": "http://wagerfield.github.io/parallax/",
"author": "Matthew Wagerfield <[email protected]>",
Expand Down
31 changes: 22 additions & 9 deletions source/jquery.parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@
position:'relative'
});
}

// Hardware Accelerate Context
this.accelerate(this.$context);

// Setup
this.updateLayers();
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Plugin.prototype.updateLayers = function() {

// Cache Layer Elements
this.$layers = this.$context.find('.layer');
this.depths = [];

// Configure Layer Styles
this.$layers.css({
position:'absolute',
display:'block',
Expand All @@ -197,19 +215,13 @@
position:'relative'
});

// Hardware Accelerate Layers
this.accelerate(this.$layers);

// Cache Depths
this.$layers.each($.proxy(function(index, element) {
this.depths.push($(element).data('depth') || 0);
}, this));

// Hardware Accelerate Elements
this.accelerate(this.$context);
this.accelerate(this.$layers);

// Setup
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Plugin.prototype.updateDimensions = function() {
Expand Down Expand Up @@ -459,6 +471,7 @@
var API = {
enable: Plugin.prototype.enable,
disable: Plugin.prototype.disable,
updateLayers: Plugin.prototype.updateLayers,
calibrate: Plugin.prototype.calibrate,
friction: Plugin.prototype.friction,
invert: Plugin.prototype.invert,
Expand Down
18 changes: 13 additions & 5 deletions source/parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@
this.element.style.position = 'relative';
}

// Setup
this.updateLayers();
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Parallax.prototype.updateLayers = function() {

// Cache Layer Elements
this.layers = this.element.getElementsByClassName('layer');
this.depths = [];

// Configure Layer Styles
for (var i = 0, l = this.layers.length; i < l; i++) {
var layer = this.layers[i];
Expand All @@ -233,11 +246,6 @@
// Cache Layer Depth
this.depths.push(this.data(layer, 'depth') || 0);
}

// Setup
this.updateDimensions();
this.enable();
this.queueCalibration(this.calibrationDelay);
};

Parallax.prototype.updateDimensions = function() {
Expand Down

0 comments on commit 11c7fb9

Please sign in to comment.