diff --git a/registry/blocks/spain-map/spain-map.html b/registry/blocks/spain-map/spain-map.html index cd61b334db..18ace321e2 100644 --- a/registry/blocks/spain-map/spain-map.html +++ b/registry/blocks/spain-map/spain-map.html @@ -279,9 +279,34 @@ buildTimeline(); }); + // GSAP's stagger { each, from: "center" } assigns every element a + // UNIQUE slot, ordered center-out (total span = each * (n-1)). + // anime.stagger(value, { from: "center" }) instead scales delay by + // DISTANCE from center, so equidistant pairs share a slot and the + // whole reveal finishes in about half the time. Precompute the GSAP + // rank order (sort by distance, ties lower-index-first) and hand + // anime explicit per-element delays instead. + function buildCenterStaggerRanks(count) { + var centerIdx = (count - 1) / 2; + var order = []; + for (var i = 0; i < count; i++) order.push(i); + order.sort(function (a, b) { + var da = Math.abs(a - centerIdx); + var db = Math.abs(b - centerIdx); + return da === db ? a - b : da - db; + }); + var rank = new Array(count); + for (var r = 0; r < order.length; r++) { + rank[order[r]] = r; + } + return rank; + } + function buildTimeline() { var regionPaths = regionsGroup.querySelectorAll(".region-path"); var regionLabels = labelsGroup.querySelectorAll(".region-label"); + var regionPathRanks = buildCenterStaggerRanks(regionPaths.length); + var regionLabelRanks = buildCenterStaggerRanks(regionLabels.length); tl.add( "#spain-map .headline", @@ -309,7 +334,9 @@ opacity: 1, scale: 1, duration: 400, - delay: anime.stagger(80, { from: "center" }), + delay: function (target, i) { + return regionPathRanks[i] * 80; + }, ease: "outBack(1.4)", }, 1000, @@ -320,7 +347,9 @@ { opacity: 1, duration: 300, - delay: anime.stagger(50, { from: "center" }), + delay: function (target, i) { + return regionLabelRanks[i] * 50; + }, ease: "outCubic", }, 4000, diff --git a/registry/blocks/us-map/us-map.html b/registry/blocks/us-map/us-map.html index eb89cb6f99..777658a0e5 100644 --- a/registry/blocks/us-map/us-map.html +++ b/registry/blocks/us-map/us-map.html @@ -288,9 +288,34 @@ buildTimeline(); }); + // GSAP's stagger { each, from: "center" } assigns every element a + // UNIQUE slot, ordered center-out (total span = each * (n-1)). + // anime.stagger(value, { from: "center" }) instead scales delay by + // DISTANCE from center, so equidistant pairs share a slot and the + // whole reveal finishes in about half the time. Precompute the GSAP + // rank order (sort by distance, ties lower-index-first) and hand + // anime explicit per-element delays instead. + function buildCenterStaggerRanks(count) { + const centerIdx = (count - 1) / 2; + const order = []; + for (let i = 0; i < count; i++) order.push(i); + order.sort((a, b) => { + const da = Math.abs(a - centerIdx); + const db = Math.abs(b - centerIdx); + return da === db ? a - b : da - db; + }); + const rank = new Array(count); + order.forEach((idx, r) => { + rank[idx] = r; + }); + return rank; + } + function buildTimeline() { const statePaths = statesGroup.querySelectorAll(".state-path"); const stateLabels = labelsGroup.querySelectorAll(".state-label"); + const statePathRanks = buildCenterStaggerRanks(statePaths.length); + const stateLabelRanks = buildCenterStaggerRanks(stateLabels.length); tl.add( "#us-map .headline", @@ -318,7 +343,7 @@ opacity: 1, scale: 1, duration: 400, - delay: anime.stagger(60, { from: "center" }), + delay: (target, i) => statePathRanks[i] * 60, ease: "outBack(1.4)", }, 1000, @@ -329,7 +354,7 @@ { opacity: 1, duration: 300, - delay: anime.stagger(40, { from: "center" }), + delay: (target, i) => stateLabelRanks[i] * 40, ease: "outCubic", }, 3500,