-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
240 lines (220 loc) · 6.69 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
!(function (e, n) {
"function" == typeof define && define.amd
? define(["ScrollMagic", "TweenMax", "TimelineMax"], n)
: "object" == typeof exports
? (require("gsap"), n(require("scrollmagic"), TweenMax, TimelineMax))
: n(
e.ScrollMagic || (e.jQuery && e.jQuery.ScrollMagic),
e.TweenMax || e.TweenLite,
e.TimelineMax || e.TimelineLite
);
})(this, function (e, n, o) {
"use strict";
var t = window.console || {},
r = Function.prototype.bind.call(t.error || t.log || function () {}, t);
e ||
r(
"(animation.gsap) -> ERROR: The ScrollMagic main module could not be found. Please make sure it's loaded before this plugin or use an asynchronous loader like requirejs."
),
n ||
r(
"(animation.gsap) -> ERROR: TweenLite or TweenMax could not be found. Please make sure GSAP is loaded before ScrollMagic or use an asynchronous loader like requirejs."
),
e.Scene.addOption("tweenChanges", !1, function (e) {
return !!e;
}),
e.Scene.extend(function () {
var e,
t = this,
r = function () {
t._log &&
(Array.prototype.splice.call(
arguments,
1,
0,
"(animation.gsap)",
"->"
),
t._log.apply(this, arguments));
};
t.on("progress.plugin_gsap", function () {
i();
}),
t.on("destroy.plugin_gsap", function (e) {
t.removeTween(e.reset);
});
var i = function () {
if (e) {
var n = t.progress(),
o = t.state();
e.repeat && -1 === e.repeat()
? "DURING" === o && e.paused()
? e.play()
: "DURING" === o || e.paused() || e.pause()
: n != e.progress() &&
(0 === t.duration()
? n > 0
? e.play()
: e.reverse()
: t.tweenChanges() && e.tweenTo
? e.tweenTo(n * e.duration())
: e.progress(n).pause());
}
};
(t.setTween = function (a, s, l) {
var c;
arguments.length > 1 &&
(arguments.length < 3 && ((l = s), (s = 1)), (a = n.to(a, s, l)));
try {
(c = o ? new o({ smoothChildTiming: !0 }).add(a) : a).pause();
} catch (e) {
return (
r(
1,
"ERROR calling method 'setTween()': Supplied argument is not a valid TweenObject"
),
t
);
}
if (
(e && t.removeTween(),
(e = c),
a.repeat && -1 === a.repeat() && (e.repeat(-1), e.yoyo(a.yoyo())),
t.tweenChanges() &&
!e.tweenTo &&
r(
2,
"WARNING: tweenChanges will only work if the TimelineMax object is available for ScrollMagic."
),
e && t.controller() && t.triggerElement() && t.loglevel() >= 2)
) {
var u = n.getTweensOf(t.triggerElement()),
p = t.controller().info("vertical");
u.forEach(function (e, n) {
var o = e.vars.css || e.vars;
if (
p
? void 0 !== o.top || void 0 !== o.bottom
: void 0 !== o.left || void 0 !== o.right
)
return (
r(
2,
"WARNING: Tweening the position of the trigger element affects the scene timing and should be avoided!"
),
!1
);
});
}
if (parseFloat(TweenLite.version) >= 1.14)
for (
var g,
d,
f = e.getChildren ? e.getChildren(!0, !0, !1) : [e],
w = function () {
r(
2,
"WARNING: tween was overwritten by another. To learn how to avoid this issue see here: https://github.com/janpaepke/ScrollMagic/wiki/WARNING:-tween-was-overwritten-by-another"
);
},
h = 0;
h < f.length;
h++
)
(g = f[h]),
d !== w &&
((d = g.vars.onOverwrite),
(g.vars.onOverwrite = function () {
d && d.apply(this, arguments), w.apply(this, arguments);
}));
return r(3, "added tween"), i(), t;
}),
(t.removeTween = function (n) {
return (
e &&
(n && e.progress(0).pause(),
e.kill(),
(e = void 0),
r(3, "removed tween (reset: " + (n ? "true" : "false") + ")")),
t
);
});
});
});
var html = document.documentElement;
var body = document.body;
var scroller = {
target: document.querySelector(".scroll-container"),
ease: 0.09, // <= scroll speed
endY: 0,
y: 0,
resizeRequest: 1,
scrollRequest: 0,
};
var requestId = null;
TweenLite.set(scroller.target, {
rotation: 0.01,
force3D: true,
});
window.addEventListener("load", onLoad);
function onLoad() {
updateScroller();
window.focus();
window.addEventListener("resize", onResize);
document.addEventListener("scroll", onScroll);
}
function updateScroller() {
var resized = scroller.resizeRequest > 0;
if (resized) {
var height = scroller.target.clientHeight;
body.style.height = height + "px";
scroller.resizeRequest = 0;
}
var scrollY = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
scroller.endY = scrollY;
scroller.y += (scrollY - scroller.y) * scroller.ease;
if (Math.abs(scrollY - scroller.y) < 0.05 || resized) {
scroller.y = scrollY;
scroller.scrollRequest = 0;
}
TweenLite.set(scroller.target, {
y: -scroller.y,
});
requestId =
scroller.scrollRequest > 0 ? requestAnimationFrame(updateScroller) : null;
}
function onScroll() {
scroller.scrollRequest++;
if (!requestId) {
requestId = requestAnimationFrame(updateScroller);
}
}
function onResize() {
scroller.resizeRequest++;
if (!requestId) {
requestId = requestAnimationFrame(updateScroller);
}
}
const controller = new ScrollMagic.Controller();
var forEach = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]);
}
};
var myNodeList = document.querySelectorAll(".img-loader");
forEach(myNodeList, function (index, value) {
const tween = TweenMax.to(value, 2, {
borderTopLeftRadius: "100%",
borderTopRightRadius: "100%",
delay: 0.3,
height: 0,
ease: Power2.easeOut,
});
const itemScene = new ScrollMagic.Scene({
triggerElement: value,
triggerHook: 0.6,
reverse: false,
})
.setTween(tween)
.addTo(controller);
});