|
114 | 114 | }
|
115 | 115 |
|
116 | 116 | this.$mirror = $('<div />').prependTo('body');
|
117 |
| - this.$slider = $('<img />').prependTo(this.$mirror); |
| 117 | + |
| 118 | + |
| 119 | + var slider = this.$element.find('>.parallax-slider'); |
| 120 | + |
| 121 | + if (slider.length == 0) |
| 122 | + this.$slider = $('<img />').prependTo(this.$mirror); |
| 123 | + else |
| 124 | + this.$slider = slider.prependTo(this.$mirror) |
118 | 125 |
|
119 | 126 | this.$mirror.addClass('parallax-mirror').css({
|
120 | 127 | visibility: 'hidden',
|
|
140 | 147 |
|
141 | 148 | this.$slider[0].src = this.imageSrc;
|
142 | 149 |
|
143 |
| - if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete) { |
| 150 | + if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete || slider.length > 0) { |
144 | 151 | this.$slider.trigger('load');
|
145 | 152 | }
|
146 | 153 |
|
|
263 | 270 |
|
264 | 271 | var $doc = $(document), $win = $(window);
|
265 | 272 |
|
| 273 | + var loadDimensions = function() { |
| 274 | + Parallax.winHeight = $win.height(); |
| 275 | + Parallax.winWidth = $win.width(); |
| 276 | + Parallax.docHeight = $doc.height(); |
| 277 | + Parallax.docWidth = $doc.width(); |
| 278 | + }; |
| 279 | + |
| 280 | + var loadScrollPosition = function() { |
| 281 | + var winScrollTop = $win.scrollTop(); |
| 282 | + var scrollTopMax = Parallax.docHeight - Parallax.winHeight; |
| 283 | + var scrollLeftMax = Parallax.docWidth - Parallax.winWidth; |
| 284 | + Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, winScrollTop)); |
| 285 | + Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft())); |
| 286 | + Parallax.overScroll = Math.max($win.scrollTop() - scrollTopMax, Math.min(winScrollTop, 0)); |
| 287 | + }; |
| 288 | + |
266 | 289 | $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(); |
271 |
| - Parallax.isFresh = false; |
272 |
| - Parallax.requestRender(); |
273 |
| - }) |
274 |
| - .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)); |
280 |
| - Parallax.requestRender(); |
281 |
| - }); |
| 290 | + loadDimensions(); |
| 291 | + Parallax.isFresh = false; |
| 292 | + Parallax.requestRender(); |
| 293 | + }) |
| 294 | + .on('scroll.px.parallax load.px.parallax', function() { |
| 295 | + loadScrollPosition(); |
| 296 | + Parallax.requestRender(); |
| 297 | + }); |
| 298 | + |
| 299 | + loadDimensions(); |
| 300 | + loadScrollPosition(); |
282 | 301 |
|
283 | 302 | this.isReady = true;
|
284 | 303 | },
|
|
0 commit comments