Skip to content

Commit 76dfa35

Browse files
author
Geoffrey Signorato
committed
#26 separate CSS transition and transform to avoid buggy effect on loadtime
1 parent 149ca03 commit 76dfa35

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/instances/parallax.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ParallaxInstance {
3636
this.wrapElement(this.element);
3737
}
3838

39-
// apply the default style on the image
40-
this.setStyle();
39+
// apply the transform style on the image
40+
this.setTransformCSS();
4141

4242
// get the current element offset
4343
this.getElementOffset();
@@ -51,6 +51,15 @@ class ParallaxInstance {
5151
// apply its translation even if not visible for the first init
5252
this.animate();
5353

54+
// if a delay has been set
55+
if (this.settings.delay > 0) {
56+
// apply a timeout to avoid buggy effect
57+
setTimeout(() => {
58+
// apply the transition style on the image
59+
this.setTransitionCSS();
60+
}, 10);
61+
}
62+
5463
// for some reason, <picture> are init an infinite time on windows OS
5564
this.isInit = true;
5665
}
@@ -80,23 +89,23 @@ class ParallaxInstance {
8089
}
8190

8291
// apply default style on element
83-
setStyle() {
92+
setTransformCSS() {
8493
if (this.settings.overflow === false) {
8594
// if overflow option is set to false
8695
// add scale style so the image can be translated without getting out of its container
8796
this.element.style[cssTransform] = `scale(${this.settings.scale})`;
8897
}
8998

90-
if (this.settings.delay > 0) {
91-
// if delay option is set to true
92-
// add transition option
93-
this.element.style.transition = `transform ${this.settings.delay}s ${this.settings.transition}`;
94-
}
95-
9699
// add will-change CSS property to improve perfomance
97100
this.element.style.willChange = 'transform';
98101
}
99102

103+
// apply the transition effet
104+
setTransitionCSS() {
105+
// add transition option
106+
this.element.style.transition = `transform ${this.settings.delay}s ${this.settings.transition}`;
107+
}
108+
100109
// remove style of the element
101110
unSetStyle() {
102111
// remove will change inline style

0 commit comments

Comments
 (0)