|
18 | 18 | this.element.style.transform = 'translateY(' + pixels + 'px)'; |
19 | 19 | }; |
20 | 20 |
|
21 | | -function getNumber (start, end, easing, ratio) { |
| 21 | +function getNumber (field, options, ratio) { |
| 22 | +var easing = options.easing[field]; |
| 23 | +var start = options.start[field]; |
| 24 | +var end = options.end[field]; |
| 25 | + |
22 | 26 | if (easing) { |
23 | 27 | ratio = easing(ratio); |
24 | 28 | } |
|
46 | 50 | OptionsParallax.prototype.handleScroll = function (ratio) { |
47 | 51 | var transformString = 'translate3D('; |
48 | 52 | if (this.options.end.x) { |
49 | | -transformString += getNumber( |
50 | | -this.options.start.x, |
51 | | -this.options.end.x, |
52 | | -this.options.easing.x, |
53 | | -ratio |
54 | | -) + 'px,'; |
| 53 | +transformString += getNumber('x', this.options, ratio) + 'px,'; |
55 | 54 | } else { |
56 | 55 | transformString += '0px,'; |
57 | 56 | } |
58 | 57 | if (this.options.end.y) { |
59 | | -transformString += getNumber( |
60 | | -this.options.start.y, |
61 | | -this.options.end.y, |
62 | | -this.options.easing.y, |
63 | | -ratio |
64 | | -) + 'px,'; |
| 58 | +transformString += getNumber('y', this.options, ratio) + 'px,'; |
65 | 59 | } else { |
66 | 60 | transformString += '0px,'; |
67 | 61 | } |
68 | 62 | if (this.options.end.z) { |
69 | | -transformString += getNumber( |
70 | | -this.options.start.z, |
71 | | -this.options.end.z, |
72 | | -this.options.easing.z, |
73 | | -ratio |
74 | | -) + 'px)'; |
| 63 | +transformString += getNumber('z', this.options, ratio) + 'px)'; |
75 | 64 | } else { |
76 | 65 | transformString += '0px)'; |
77 | 66 | } |
78 | 67 |
|
79 | 68 | if (this.options.end.rotate) { |
80 | | -transformString += ' rotate(' + getNumber( |
81 | | -this.options.start.rotate, |
82 | | -this.options.end.rotate, |
83 | | -this.options.easing.rotate, |
84 | | -ratio |
85 | | -) + 'deg)'; |
| 69 | +transformString += ' rotate(' + getNumber('rotate', this.options, ratio) + 'deg)'; |
86 | 70 | } |
87 | 71 |
|
88 | 72 | if (this.options.end.scale) { |
89 | | -transformString += ' scale(' + getNumber( |
90 | | -this.options.start.scale, |
91 | | -this.options.end.scale, |
92 | | -this.options.easing.rotate, |
93 | | -ratio |
94 | | -) + ')'; |
| 73 | +transformString += ' scale(' + getNumber('scale', this.options, ratio) + ')'; |
95 | 74 | } |
96 | 75 | this.element.style.transform = transformString; |
| 76 | + |
| 77 | +if (this.options.end.opacity) { |
| 78 | +this.element.style.opacity = getNumber('opacity', this.options, ratio); |
| 79 | +} |
97 | 80 | }; |
98 | 81 |
|
99 | 82 | function Root (element, offsets) { |
|
0 commit comments