Skip to content

Commit 6c32735

Browse files
committed
bugfix and formatting
preventing that the ImageSrc is added to the slider if it already existed in the DOM Tree
1 parent 268632f commit 6c32735

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

parallax.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
1616
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
1717
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
18-
|| window[vendors[x]+'CancelRequestAnimationFrame'];
18+
|| window[vendors[x]+'CancelRequestAnimationFrame'];
1919
}
2020

2121
if (!window.requestAnimationFrame)
@@ -115,13 +115,15 @@
115115

116116
this.$mirror = $('<div />').prependTo('body');
117117

118-
119118
var slider = this.$element.find('>.parallax-slider');
119+
var sliderExisted = false;
120120

121121
if (slider.length == 0)
122122
this.$slider = $('<img />').prependTo(this.$mirror);
123-
else
123+
else {
124124
this.$slider = slider.prependTo(this.$mirror)
125+
sliderExisted = true;
126+
}
125127

126128
this.$mirror.addClass('parallax-mirror').css({
127129
visibility: 'hidden',
@@ -145,7 +147,8 @@
145147
Parallax.requestRender();
146148
});
147149

148-
this.$slider[0].src = this.imageSrc;
150+
if (!sliderExisted)
151+
this.$slider[0].src = this.imageSrc;
149152

150153
if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete || slider.length > 0) {
151154
this.$slider.trigger('load');
@@ -287,14 +290,14 @@
287290
};
288291

289292
$win.on('resize.px.parallax load.px.parallax', function() {
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-
});
293+
loadDimensions();
294+
Parallax.isFresh = false;
295+
Parallax.requestRender();
296+
})
297+
.on('scroll.px.parallax load.px.parallax', function() {
298+
loadScrollPosition();
299+
Parallax.requestRender();
300+
});
298301

299302
loadDimensions();
300303
loadScrollPosition();

0 commit comments

Comments
 (0)