How to Use TranslateY Percentage Values for Position-Independent Animations
The skills repository converts Y-percentage values (e.g., 50%) into computed pixel offsets at runtime, ensuring animations behave consistently regardless of element positioning or container layout.
Position-independent animations are critical for responsive UI design. The emilkowalski/skills repository solves a common problem: translateY percentage values resolve relative to the element's own height, causing unpredictable motion when containers resize or positioning contexts change. This guide explains how the repository's review-animations skill translates these percentages into stable pixel values.
How Y-Percentage Translation Works
The conversion pipeline in skills/review-animations/ operates in three stages:
- Detection – Identifies percentage syntax in animation definitions.
- Calculation – Computes pixel offsets from the target element's computed height (or viewport height for root-level elements).
- Replacement – Substitutes the percentage with the runtime pixel value before emission to the browser.
This approach guarantees identical animation behavior across absolute, relative, flex, and grid layouts because calculations use current layout metrics at execution time.
Key Design Principles
The translation function follows strict functional programming constraints:
- Pure function – No side effects; safe for reuse across skills.
- Strongly typed – Compatible with both JavaScript and TypeScript.
- Runtime calculation – Defers computation until layout metrics are finalized.
Performance note: Calculating at runtime prevents the "jumping" artifacts common when container heights change during responsive transitions.
Implementation Examples
Direct Helper Function Usage
// From skills/review-animations/translate
import { translateYPercent } from 'skills/review-animations/translate';
const element = document.querySelector('.hero');
const percent = '30%';
const pixels = translateYPercent(percent, element);
// Result: "96px" on a 320px tall container
element.animate(
[{ transform: `translateY(${pixels})` }],
{
fill: 'forwards',
duration: 400,
easing: 'ease-out'
}
);
Pipeline Integration with TypeScript
import { AnimationStep, applyTranslation } from 'skills/review-animations';
export const normalizeYPercent = (step: AnimationStep): AnimationStep => {
if (step.props?.y?.endsWith('%')) {
const px = translateYPercent(step.props.y, step.target);
return {
...step,
props: { ...step.props, y: `${px}px` }
};
}
return step;
};
// Register for automatic processing
pipeline.use(normalizeYPercent);
CLI Batch Processing
npx skills@latest run review-animations ./src/styles.css \
--transform-y-percent
This command rewrites all translateY(XX%) declarations to translateY(YYpx) based on detected container dimensions in the source CSS.
Source Files and Architecture
| File | Purpose |
|---|---|
skills/review-animations/SKILL.md |
Skill definition, animation rules, and percentage translation methodology |
skills/review-animations/STANDARDS.md |
Official quality standards including Y-percentage handling |
skills/improve-animations/SKILL.md |
Reuse patterns for auditing existing codebases |
README.md |
Repository overview and installation instructions |
The translation utility spans multiple skills. The improve-animations skill—defined in skills/improve-animations/SKILL.md—reuses the same helper when analyzing existing animations for potential issues.
Why TranslateY Percentage Values Require Conversion
Percentage-based vertical motion creates three specific problems in modern layouts:
- Relative reference ambiguity –
translateY(50%)calculates against the element's height, not its container's. - Layout thrashing – Dynamic content changes trigger recalculation mid-animation.
- Responsive fragility – Same percentage yields different visual results across breakpoints.
By translating to pixels at runtime, the skills repository preserves designer-friendly percentage thinking while delivering engine-friendly absolute values.
Summary
- The
translateYPercentfunction inskills/review-animations/translateconverts percentages to pixels using live layout metrics. - The review-animations skill automatically applies this conversion through its three-stage pipeline.
- Pure function design enables safe reuse in
improve-animationsand custom skill pipelines. - CLI and programmatic APIs provide flexible integration paths for existing projects.
Frequently Asked Questions
What makes translateY percentage values position-dependent?
The CSS transform: translateY(N%) property calculates percentages relative to the element's own border box height. When that height changes—due to content, container constraints, or responsive breakpoints—the same percentage produces different pixel displacements. The skills repository eliminates this coupling by resolving percentages to absolute pixels at animation start time.
Can I use this with frameworks like React or Vue?
Yes. The translation helper is framework-agnostic. Import translateYPercent directly into component logic, or register normalizeYPercent as a pipeline step that processes animation configurations before they reach the DOM. The TypeScript types are fully compatible with props-based animation libraries.
How does runtime translation affect animation performance?
The calculation executes once per animation initialization, not per frame. Because pixels are computed using getBoundingClientRect() or equivalent measurements during the style recalculation phase, the subsequent animation runs entirely on the compositor with no main-thread overhead for value resolution.
Where is the source code for the translation logic?
Core implementation resides in skills/review-animations/translate (namespace). Documentation for behavior and integration patterns appears in [skills/review-animations/SKILL.md](https://github.com/emilkowalski/skills/blob/main/skills/review-animations/SKILL.md), with quality standards defined in [skills/review-animations/STANDARDS.md](https://github.com/emilkowalski/skills/blob/main/skills/review-animations/STANDARDS.md).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →