Capítulo 169 de 411
gsap.utils.snap() always snaps to the closest increment/value; this helper adds a direction argument so a value snaps strictly to the next greater or next lesser increment instead.
gsap.utils.snap(); accepts either a numeric increment or a sorted array of allowed values.1 = snap to the closest value greater than the input, -1 = closest lesser, falsy = normal closest-match snap.let snap = gsap.utils.snap(5);
snap(2); // 0 (closest)
snap(19); // 20 (closest)
let dirSnap = getDirectionalSnapFunc(5);
dirSnap(19, 1); // 20 (next greater)
dirSnap(19, -1); // 15 (next lesser)
gsap.utils.snap()'s "closest" behavior and this helper's directional variant.