| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Vertically translate the background based on a factor of the scroll positio
n. | 2 * Vertically translate the background based on a factor of the scroll positio
n. |
| 3 */ | 3 */ |
| 4 Polymer.AppLayout.registerEffect('parallax-background', { | 4 Polymer.AppLayout.registerEffect('parallax-background', { |
| 5 /** | 5 /** |
| 6 * @param {{scalar: string}} config | 6 * @param {{scalar: string}} config |
| 7 * @this Polymer.AppLayout.ElementWithBackground | 7 * @this Polymer.AppLayout.ElementWithBackground |
| 8 */ | 8 */ |
| 9 setUp: function setUp(config) { | 9 setUp: function setUp(config) { |
| 10 var fx = {}; |
| 10 var scalar = parseFloat(config.scalar); | 11 var scalar = parseFloat(config.scalar); |
| 11 | 12 fx.background = this._getDOMRef('background'); |
| 12 this._deltaBg = this.$.backgroundFrontLayer.offsetHeight - this.$.backgrou
nd.offsetHeight; | 13 fx.backgroundFrontLayer = this._getDOMRef('backgroundFrontLayer'); |
| 13 if (this._deltaBg === 0) { | 14 fx.backgroundRearLayer = this._getDOMRef('backgroundRearLayer'); |
| 15 fx.deltaBg = fx.backgroundFrontLayer.offsetHeight - fx.background.offsetHe
ight; |
| 16 if (fx.deltaBg === 0) { |
| 14 if (isNaN(scalar)) { | 17 if (isNaN(scalar)) { |
| 15 scalar = 0.8; | 18 scalar = 0.8; |
| 16 } | 19 } |
| 17 this._deltaBg = this._dHeight * scalar; | 20 fx.deltaBg = this._dHeight * scalar; |
| 18 } else { | 21 } else { |
| 19 if (isNaN(scalar)) { | 22 if (isNaN(scalar)) { |
| 20 scalar = 1; | 23 scalar = 1; |
| 21 } | 24 } |
| 22 this._deltaBg = this._deltaBg * scalar; | 25 fx.deltaBg = fx.deltaBg * scalar; |
| 26 } |
| 27 this._fxParallaxBackground = fx; |
| 28 }, |
| 29 /** @this Polymer.AppLayout.ElementWithBackground */ |
| 30 run: function run(p, y) { |
| 31 var fx = this._fxParallaxBackground; |
| 32 this.transform('translate3d(0px, ' + (fx.deltaBg * Math.min(1, p)) + 'px,
0px)', fx.backgroundFrontLayer); |
| 33 if (fx.backgroundRearLayer) { |
| 34 this.transform('translate3d(0px, ' + (fx.deltaBg * Math.min(1, p)) + 'px
, 0px)', fx.backgroundRearLayer); |
| 23 } | 35 } |
| 24 }, | 36 }, |
| 25 /** @this Polymer.AppLayout.ElementWithBackground */ | 37 /** @this Polymer.AppLayout.ElementWithBackground */ |
| 26 tearDown: function tearDown() { | 38 tearDown: function tearDown() { |
| 27 delete this._deltaBg; | 39 delete this._fxParallaxBackground; |
| 28 }, | |
| 29 /** @this Polymer.AppLayout.ElementWithBackground */ | |
| 30 run: function run(p, y) { | |
| 31 this.transform('translate3d(0px, ' + (this._deltaBg * Math.min(1, p)) + 'p
x, 0px)', this.$.backgroundFrontLayer); | |
| 32 if (this.$.backgroundRearLayer) { | |
| 33 this.transform('translate3d(0px, ' + (this._deltaBg * Math.min(1, p)) +
'px, 0px)', this.$.backgroundRearLayer); | |
| 34 } | |
| 35 } | 40 } |
| 36 }); | 41 }); |
| OLD | NEW |