Newer
Older
Arnav Pant
committed
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.window = global.window || {}));
}(this, (function (exports) { 'use strict';
/*!
* ScrollToPlugin 3.12.7
* https://gsap.com
*
* @license Copyright 2008-2025, GreenSock. All rights reserved.
* Subject to the terms at https://gsap.com/standard-license or for
* Club GSAP members, the agreement issued with that membership.
* @author: Jack Doyle, jack@greensock.com
*/
var gsap,
_coreInitted,
_window,
_docEl,
_body,
_toArray,
_config,
ScrollTrigger,
_windowExists = function _windowExists() {
return typeof window !== "undefined";
},
_getGSAP = function _getGSAP() {
return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
},
_isString = function _isString(value) {
return typeof value === "string";
},
_isFunction = function _isFunction(value) {
return typeof value === "function";
},
_max = function _max(element, axis) {
var dim = axis === "x" ? "Width" : "Height",
scroll = "scroll" + dim,
client = "client" + dim;
return element === _window || element === _docEl || element === _body ? Math.max(_docEl[scroll], _body[scroll]) - (_window["inner" + dim] || _docEl[client] || _body[client]) : element[scroll] - element["offset" + dim];
},
_buildGetter = function _buildGetter(e, axis) {
var p = "scroll" + (axis === "x" ? "Left" : "Top");
if (e === _window) {
if (e.pageXOffset != null) {
p = "page" + axis.toUpperCase() + "Offset";
} else {
e = _docEl[p] != null ? _docEl : _body;
}
}
return function () {
return e[p];
};
},
_clean = function _clean(value, index, target, targets) {
_isFunction(value) && (value = value(index, target, targets));
if (typeof value !== "object") {
return _isString(value) && value !== "max" && value.charAt(1) !== "=" ? {
x: value,
y: value
} : {
y: value
};
} else if (value.nodeType) {
return {
y: value,
x: value
};
} else {
var result = {},
p;
for (p in value) {
result[p] = p !== "onAutoKill" && _isFunction(value[p]) ? value[p](index, target, targets) : value[p];
}
return result;
}
},
_getOffset = function _getOffset(element, container) {
element = _toArray(element)[0];
if (!element || !element.getBoundingClientRect) {
return console.warn("scrollTo target doesn't exist. Using 0") || {
x: 0,
y: 0
};
}
var rect = element.getBoundingClientRect(),
isRoot = !container || container === _window || container === _body,
cRect = isRoot ? {
top: _docEl.clientTop - (_window.pageYOffset || _docEl.scrollTop || _body.scrollTop || 0),
left: _docEl.clientLeft - (_window.pageXOffset || _docEl.scrollLeft || _body.scrollLeft || 0)
} : container.getBoundingClientRect(),
offsets = {
x: rect.left - cRect.left,
y: rect.top - cRect.top
};
if (!isRoot && container) {
offsets.x += _buildGetter(container, "x")();
offsets.y += _buildGetter(container, "y")();
}
return offsets;
},
_parseVal = function _parseVal(value, target, axis, currentVal, offset) {
return !isNaN(value) && typeof value !== "object" ? parseFloat(value) - offset : _isString(value) && value.charAt(1) === "=" ? parseFloat(value.substr(2)) * (value.charAt(0) === "-" ? -1 : 1) + currentVal - offset : value === "max" ? _max(target, axis) - offset : Math.min(_max(target, axis), _getOffset(value, target)[axis] - offset);
},
_initCore = function _initCore() {
gsap = _getGSAP();
if (_windowExists() && gsap && typeof document !== "undefined" && document.body) {
_window = window;
_body = document.body;
_docEl = document.documentElement;
_toArray = gsap.utils.toArray;
gsap.config({
autoKillThreshold: 7
});
_config = gsap.config();
_coreInitted = 1;
}
};
var ScrollToPlugin = {
version: "3.12.7",
name: "scrollTo",
rawVars: 1,
register: function register(core) {
gsap = core;
_initCore();
},
init: function init(target, value, tween, index, targets) {
_coreInitted || _initCore();
var data = this,
snapType = gsap.getProperty(target, "scrollSnapType");
data.isWin = target === _window;
data.target = target;
data.tween = tween;
value = _clean(value, index, target, targets);
data.vars = value;
data.autoKill = !!("autoKill" in value ? value : _config).autoKill;
data.getX = _buildGetter(target, "x");
data.getY = _buildGetter(target, "y");
data.x = data.xPrev = data.getX();
data.y = data.yPrev = data.getY();
ScrollTrigger || (ScrollTrigger = gsap.core.globals().ScrollTrigger);
gsap.getProperty(target, "scrollBehavior") === "smooth" && gsap.set(target, {
scrollBehavior: "auto"
});
if (snapType && snapType !== "none") {
data.snap = 1;
data.snapInline = target.style.scrollSnapType;
target.style.scrollSnapType = "none";
}
if (value.x != null) {
data.add(data, "x", data.x, _parseVal(value.x, target, "x", data.x, value.offsetX || 0), index, targets);
data._props.push("scrollTo_x");
} else {
data.skipX = 1;
}
if (value.y != null) {
data.add(data, "y", data.y, _parseVal(value.y, target, "y", data.y, value.offsetY || 0), index, targets);
data._props.push("scrollTo_y");
} else {
data.skipY = 1;
}
},
render: function render(ratio, data) {
var pt = data._pt,
target = data.target,
tween = data.tween,
autoKill = data.autoKill,
xPrev = data.xPrev,
yPrev = data.yPrev,
isWin = data.isWin,
snap = data.snap,
snapInline = data.snapInline,
x,
y,
yDif,
xDif,
threshold;
while (pt) {
pt.r(ratio, pt.d);
pt = pt._next;
}
x = isWin || !data.skipX ? data.getX() : xPrev;
y = isWin || !data.skipY ? data.getY() : yPrev;
yDif = y - yPrev;
xDif = x - xPrev;
threshold = _config.autoKillThreshold;
if (data.x < 0) {
data.x = 0;
}
if (data.y < 0) {
data.y = 0;
}
if (autoKill) {
if (!data.skipX && (xDif > threshold || xDif < -threshold) && x < _max(target, "x")) {
data.skipX = 1;
}
if (!data.skipY && (yDif > threshold || yDif < -threshold) && y < _max(target, "y")) {
data.skipY = 1;
}
if (data.skipX && data.skipY) {
tween.kill();
data.vars.onAutoKill && data.vars.onAutoKill.apply(tween, data.vars.onAutoKillParams || []);
}
}
if (isWin) {
_window.scrollTo(!data.skipX ? data.x : x, !data.skipY ? data.y : y);
} else {
data.skipY || (target.scrollTop = data.y);
data.skipX || (target.scrollLeft = data.x);
}
if (snap && (ratio === 1 || ratio === 0)) {
y = target.scrollTop;
x = target.scrollLeft;
snapInline ? target.style.scrollSnapType = snapInline : target.style.removeProperty("scroll-snap-type");
target.scrollTop = y + 1;
target.scrollLeft = x + 1;
target.scrollTop = y;
target.scrollLeft = x;
}
data.xPrev = data.x;
data.yPrev = data.y;
ScrollTrigger && ScrollTrigger.update();
},
kill: function kill(property) {
var both = property === "scrollTo",
i = this._props.indexOf(property);
if (both || property === "scrollTo_x") {
this.skipX = 1;
}
if (both || property === "scrollTo_y") {
this.skipY = 1;
}
i > -1 && this._props.splice(i, 1);
return !this._props.length;
}
};
ScrollToPlugin.max = _max;
ScrollToPlugin.getOffset = _getOffset;
ScrollToPlugin.buildGetter = _buildGetter;
ScrollToPlugin.config = function (vars) {
_config || _initCore() || (_config = gsap.config());
for (var p in vars) {
_config[p] = vars[p];
}
};
_getGSAP() && gsap.registerPlugin(ScrollToPlugin);
exports.ScrollToPlugin = ScrollToPlugin;
exports.default = ScrollToPlugin;
Object.defineProperty(exports, '__esModule', { value: true });
})));