Skip to content

Commit 6da1876

Browse files
committed
Fix viewport element detection, allow nested parallax
1 parent e67819c commit 6da1876

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

stellar.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
_defineElements: function() {
139139
this.$scrollElement = $(this.element);
140140
this.$element = this.element === window ? $('body') : this.$scrollElement;
141-
this.$viewportElement = (this.options.viewportElement !== undefined ? $(this.options.viewportElement) : (this.$scrollElement[0] === window ? this.$scrollElement : this.$scrollElement.parent()) );
141+
this.$viewportElement = (this.options.viewportElement !== undefined ? $(this.options.viewportElement) : (this.$scrollElement[0] === window || this.options.scrollProperty.indexOf('scroll') === 0 ? this.$scrollElement : this.$scrollElement.parent()) );
142142
},
143143
_defineGetters: function() {
144144
var self = this;
@@ -199,6 +199,12 @@
199199
scrollLeft = this._getScrollLeft(),
200200
scrollTop = this._getScrollTop();
201201

202+
if (this.particles !== undefined) {
203+
for (var i = this.particles.length - 1; i >= 0; i--) {
204+
this.particles[i].$element.data('stellar-elementIsActive', undefined);
205+
}
206+
}
207+
202208
this.particles = [];
203209

204210
if (!this.options.parallaxElements) return;
@@ -217,6 +223,13 @@
217223
tempParentOffsetLeft = 0,
218224
tempParentOffsetTop = 0;
219225

226+
// Ensure this element isn't already part of another scrolling element
227+
if ($this.data('stellar-elementIsActive') === undefined) {
228+
$this.data('stellar-elementIsActive', true);
229+
} else {
230+
return;
231+
}
232+
220233
self.options.showElement($this);
221234

222235
// Save/restore the original top and left CSS values in case we refresh the particles
@@ -280,6 +293,12 @@
280293
scrollTop = this._getScrollTop(),
281294
$backgroundElements;
282295

296+
if (this.background !== undefined) {
297+
for (var i = this.backgrounds.length - 1; i >= 0; i--) {
298+
this.backgrounds[i].$element.data('stellar-backgroundIsActive', undefined);
299+
}
300+
}
301+
283302
this.backgrounds = [];
284303

285304
if (!this.options.parallaxBackgrounds) return;
@@ -300,6 +319,13 @@
300319
offsetLeft,
301320
offsetTop;
302321

322+
// Ensure this element isn't already part of another scrolling element
323+
if ($this.data('stellar-backgroundIsActive') === undefined) {
324+
$this.data('stellar-backgroundIsActive', true);
325+
} else {
326+
return;
327+
}
328+
303329
offsetLeft = $this.offset().left - parseInt($this.css('margin-left'), 10) - scrollLeft;
304330
offsetTop = $this.offset().top - parseInt($this.css('margin-top'), 10) - scrollTop;
305331

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy