|
15 | 15 | for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
16 | 16 | window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
|
17 | 17 | window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|
18 |
| - || window[vendors[x]+'CancelRequestAnimationFrame']; |
| 18 | + || window[vendors[x]+'CancelRequestAnimationFrame']; |
19 | 19 | }
|
20 | 20 |
|
21 | 21 | if (!window.requestAnimationFrame)
|
|
92 | 92 | this.positionY + (isNaN(this.positionY)? '' : 'px');
|
93 | 93 |
|
94 | 94 | if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
|
95 |
| - if (this.iosFix && !this.$element.is('img')) { |
| 95 | + if (this.imageSrc && this.iosFix && !this.$element.is('img')) { |
96 | 96 | this.$element.css({
|
97 | 97 | backgroundImage: 'url(' + this.imageSrc + ')',
|
98 | 98 | backgroundSize: 'cover',
|
|
103 | 103 | }
|
104 | 104 |
|
105 | 105 | if (navigator.userAgent.match(/(Android)/)) {
|
106 |
| - if (this.androidFix && !this.$element.is('img')) { |
| 106 | + if (this.imageSrc && this.androidFix && !this.$element.is('img')) { |
107 | 107 | this.$element.css({
|
108 | 108 | backgroundImage: 'url(' + this.imageSrc + ')',
|
109 | 109 | backgroundSize: 'cover',
|
|
114 | 114 | }
|
115 | 115 |
|
116 | 116 | this.$mirror = $('<div />').prependTo('body');
|
117 |
| - this.$slider = $('<img />').prependTo(this.$mirror); |
| 117 | + |
| 118 | + var slider = this.$element.find('>.parallax-slider'); |
| 119 | + var sliderExisted = false; |
| 120 | + |
| 121 | + if (slider.length == 0) |
| 122 | + this.$slider = $('<img />').prependTo(this.$mirror); |
| 123 | + else { |
| 124 | + this.$slider = slider.prependTo(this.$mirror) |
| 125 | + sliderExisted = true; |
| 126 | + } |
118 | 127 |
|
119 | 128 | this.$mirror.addClass('parallax-mirror').css({
|
120 | 129 | visibility: 'hidden',
|
|
138 | 147 | Parallax.requestRender();
|
139 | 148 | });
|
140 | 149 |
|
141 |
| - this.$slider[0].src = this.imageSrc; |
| 150 | + if (!sliderExisted) |
| 151 | + this.$slider[0].src = this.imageSrc; |
142 | 152 |
|
143 |
| - if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete) { |
| 153 | + if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete || slider.length > 0) { |
144 | 154 | this.$slider.trigger('load');
|
145 | 155 | }
|
146 | 156 |
|
|
263 | 273 |
|
264 | 274 | var $doc = $(document), $win = $(window);
|
265 | 275 |
|
| 276 | + var loadDimensions = function() { |
| 277 | + Parallax.winHeight = $win.height(); |
| 278 | + Parallax.winWidth = $win.width(); |
| 279 | + Parallax.docHeight = $doc.height(); |
| 280 | + Parallax.docWidth = $doc.width(); |
| 281 | + }; |
| 282 | + |
| 283 | + var loadScrollPosition = function() { |
| 284 | + var winScrollTop = $win.scrollTop(); |
| 285 | + var scrollTopMax = Parallax.docHeight - Parallax.winHeight; |
| 286 | + var scrollLeftMax = Parallax.docWidth - Parallax.winWidth; |
| 287 | + Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, winScrollTop)); |
| 288 | + Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft())); |
| 289 | + Parallax.overScroll = Math.max($win.scrollTop() - scrollTopMax, Math.min(winScrollTop, 0)); |
| 290 | + }; |
| 291 | + |
266 | 292 | $win.on('resize.px.parallax load.px.parallax', function() {
|
267 |
| - Parallax.winHeight = $win.height(); |
268 |
| - Parallax.winWidth = $win.width(); |
269 |
| - Parallax.docHeight = $doc.height(); |
270 |
| - Parallax.docWidth = $doc.width(); |
| 293 | + loadDimensions(); |
271 | 294 | Parallax.isFresh = false;
|
272 | 295 | Parallax.requestRender();
|
273 | 296 | })
|
274 | 297 | .on('scroll.px.parallax load.px.parallax', function() {
|
275 |
| - var scrollTopMax = Parallax.docHeight - Parallax.winHeight; |
276 |
| - var scrollLeftMax = Parallax.docWidth - Parallax.winWidth; |
277 |
| - Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, $win.scrollTop())); |
278 |
| - Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft())); |
279 |
| - Parallax.overScroll = Math.max($win.scrollTop() - scrollTopMax, Math.min($win.scrollTop(), 0)); |
| 298 | + loadScrollPosition(); |
280 | 299 | Parallax.requestRender();
|
281 | 300 | });
|
282 | 301 |
|
| 302 | + loadDimensions(); |
| 303 | + loadScrollPosition(); |
| 304 | + |
283 | 305 | this.isReady = true;
|
284 | 306 | },
|
285 | 307 |
|
|
0 commit comments