|
28 | 28 | scrollProperty = {
|
29 | 29 | scroll: {
|
30 | 30 | getLeft: function($elem) { return $elem.scrollLeft(); },
|
31 |
| - setLeft: function($elem, val) { $elem.scrollLeft(val); }, |
32 |
| - |
33 |
| - getTop: function($elem) { return $elem.scrollTop(); }, |
34 |
| - setTop: function($elem, val) { $elem.scrollTop(val); } |
| 31 | + getTop: function($elem) { return $elem.scrollTop(); } |
35 | 32 | },
|
36 | 33 | position: {
|
37 | 34 | getLeft: function($elem) { return parseInt($elem.css('left'), 10) * -1; },
|
|
174 | 171 | },
|
175 | 172 | _defineSetters: function() {
|
176 | 173 | var self = this,
|
177 |
| - scrollPropertyAdapter = scrollProperty[self.options.scrollProperty], |
178 |
| - positionPropertyAdapter = positionProperty[self.options.positionProperty], |
179 |
| - setScrollLeft = scrollPropertyAdapter.setLeft, |
180 |
| - setScrollTop = scrollPropertyAdapter.setTop; |
181 |
| - |
182 |
| - this._setScrollLeft = (typeof setScrollLeft === 'function' ? function(val) { |
183 |
| - setScrollLeft(self.$scrollElement, val); |
184 |
| - } : $.noop); |
185 |
| - |
186 |
| - this._setScrollTop = (typeof setScrollTop === 'function' ? function(val) { |
187 |
| - setScrollTop(self.$scrollElement, val); |
188 |
| - } : $.noop); |
| 174 | + positionPropertyAdapter = positionProperty[self.options.positionProperty]; |
189 | 175 |
|
190 | 176 | this._setPosition = positionPropertyAdapter.setPosition ||
|
191 | 177 | function($elem, left, startingLeft, top, startingTop) {
|
|
217 | 203 | });
|
218 | 204 | },
|
219 | 205 | refresh: function(options) {
|
220 |
| - var self = this, |
221 |
| - oldLeft = self._getScrollLeft(), |
222 |
| - oldTop = self._getScrollTop(); |
223 |
| - |
224 |
| - this._setScrollLeft(0); |
225 |
| - this._setScrollTop(0); |
| 206 | + if (!options || !options.firstLoad) { |
| 207 | + this._reset(); |
| 208 | + } |
226 | 209 |
|
227 | 210 | this._setOffsets();
|
228 | 211 | this._findParticles();
|
229 | 212 | this._findBackgrounds();
|
230 |
| - |
231 |
| - // Fix for WebKit background rendering bug |
232 |
| - if (options && options.firstLoad && /WebKit/.test(navigator.userAgent)) { |
233 |
| - $(window).load(function() { |
234 |
| - var oldLeft = self._getScrollLeft(), |
235 |
| - oldTop = self._getScrollTop(); |
236 |
| - |
237 |
| - self._setScrollLeft(oldLeft + 1); |
238 |
| - self._setScrollTop(oldTop + 1); |
239 |
| - |
240 |
| - self._setScrollLeft(oldLeft); |
241 |
| - self._setScrollTop(oldTop); |
242 |
| - }); |
243 |
| - } |
244 |
| - |
245 |
| - this._setScrollLeft(oldLeft); |
246 |
| - this._setScrollTop(oldTop); |
247 | 213 | },
|
248 | 214 | _detectViewport: function() {
|
249 | 215 | var viewportOffsets = this.$viewportElement.offset(),
|
|
449 | 415 | });
|
450 | 416 | });
|
451 | 417 | },
|
452 |
| - destroy: function() { |
| 418 | + _reset: function() { |
453 | 419 | var particle,
|
454 | 420 | startingPositionLeft,
|
455 | 421 | startingPositionTop,
|
|
470 | 436 |
|
471 | 437 | for (i = this.backgrounds.length - 1; i >= 0; i--) {
|
472 | 438 | background = this.backgrounds[i];
|
| 439 | + |
| 440 | + background.$element.data('stellar-backgroundStartingLeft', null).data('stellar-backgroundStartingTop', null); |
| 441 | + |
473 | 442 | setBackgroundPosition(background.$element, background.startingValueLeft, background.startingValueTop);
|
474 | 443 | }
|
| 444 | + }, |
| 445 | + destroy: function() { |
| 446 | + this._reset(); |
475 | 447 |
|
476 | 448 | this.$scrollElement.unbind('resize.' + this.name).unbind('scroll.' + this.name);
|
477 | 449 | this._animationLoop = $.noop;
|
|
0 commit comments