whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

Smooth SVG animation with JavaScript requestAnimationFrame

SVG is ideal for icons, charts, diagrams, and compact illustrations, but changing several attributes in a tight loop can still look abrupt. JavaScript’s requestAnimationFrame API lets an animation update in step with the browser’s rendering cycle, producing fluid movement without tying the code to arbitrary timer intervals.

The useful distinction is between smooth motion and merely frequent updates. A frame callback should calculate a small, coherent state change, apply all SVG writes together, and yield control before the next repaint. That discipline reduces visual jitter when a path, icon, or chart marker moves between two positions.

For Australian products, the test is not only a powerful office workstation. A customer may open a finance dashboard on the Sydney train, tap a product diagram on a Melbourne phone, or use a regional connection around Wagga Wagga. The interaction must remain responsive across different screen sizes, refresh rates, and network conditions.

A robust implementation therefore treats animation as state: record the current and target values, advance them predictably, and stop cleanly when the target is reached. The following sections build that pattern for SVG while keeping accessibility, browser behaviour, and maintenance costs in view.

Why frame-based animation matters

Modern browsers generally repaint at the display’s refresh rate, often 60 or 120 times per second. requestAnimationFrame schedules work for the next available frame and supplies a timestamp, so one callback can calculate elapsed time without repeatedly calling Date.now. If a frame is late, the next timestamp keeps movement aligned with real time.

Animation should remain independent of network speed because the browser already has the SVG markup and styles needed for the transition. Even when a regional Australian customer has variable broadband, the visual update is local. Network latency may delay loading the asset, but it should not govern the smoothness of a downloaded vector graphic.

Use the callback for visual writes, not heavy data processing. Parse a large response, transform a dataset, or calculate geometry before entering the loop. Once per frame, a small set of related changes is enough; unrelated layout work can cause the browser to delay presentation.

Build a reliable animation loop

The core loop needs a start time, duration, and easing function. This example translates a marker across a fixed SVG coordinate system and stops requesting frames at the endpoint.

const marker = document.querySelector("[data-marker]");
const startedAt = performance.now();
const duration = 450;
const easeOutCubic = value =>
  1 - Math.pow(1 - value, 3);

function draw(now) {
  const elapsed = Math.min(now - startedAt, duration);
  const progress = elapsed / duration;
  const eased = easeOutCubic(progress);

  marker.setAttribute(
    "transform",
    `translate(${120 * eased} 0)`
  );

  if (elapsed < duration) {
    requestAnimationFrame(draw);
  }
}

requestAnimationFrame(draw);

Read the starting timestamp from the first callback rather than creating a separate clock. Store the highest supported timestamp in a variable, calculate progress as elapsed divided by duration, clamp it to the range zero through one, then apply that progress to the relevant attributes.

A duration-based animation should finish when a tab returns from the background rather than replaying missed frames. Absolute elapsed time provides that behaviour. Long-lived browser widgets should also release their loop when removed; the same explicit lifecycle discipline described in graceful shutdown strategies can prevent stale work in server applications.

Keep SVG coordinates under control

SVG has several coordinate systems, so a rotation that looks correct in a rectangle can drift when applied to an icon. Set transform-box to fill-box and define transform-origin deliberately, or calculate in the SVG user coordinate system. Test the result across Firefox, Safari, Chrome, and Edge because small transform-origin differences are easy to miss.

Choose one representation for each property and avoid mixing CSS transforms with the transform attribute during a transition. CSS is convenient for opacity and transforms, while setAttribute works well for stroke-dashoffset and path-length effects. For a line-drawing effect, obtain the path length once and update the dash offset; do not repeat expensive geometry queries in every frame.

Batch reads before writes, and keep path measurements outside the loop. For instance, cache the total path length, derive the dash array and offset values, and then change only the offset. This prevents the animation from competing with layout, which is especially noticeable on Australian retail dashboards used with mid-range Android phones.

Handle interruption and accessibility

A transition can be interrupted at any time. If a user reverses direction, clicking the target again should not make the icon jump or queue another loop. Read the current animated value, treat it as the new starting point, cancel the previous frame request, and begin a fresh path toward the revised target.

Spring motion is useful when direction changes frequently because velocity carries into the next segment. A duration-and-easing model is simpler when every change follows the same route. Whichever model you choose, document the start state, end state, and replacement rule clearly; users should not have to infer them any more than visitors need to infer casino free drinks rules.

Define the endpoint before starting so a repeated event is harmless. For reduced-motion users, check prefers-reduced-motion with matchMedia and move immediately to the final state or use a minimal opacity change. WCAG-aligned behaviour matters for education platforms, commerce sites, and public-facing services across Australia.

Tune for mobile and Australian conditions

Performance depends on the device and the complexity of the SVG, not simply the animation API. Keep path counts modest, avoid filters and large blurred shadows during movement, and prefer transforms or stroke offsets over geometry recalculation. The same scene can look polished on a studio display but burden an older phone still used by many Australian customers.

iPhone models with high-refresh displays can expose uneven frame pacing that is hidden on a 60-hertz monitor. The device perspective in iPhone gambling apps is relevant for any team testing motion-heavy mobile interfaces, even when the product and rendering stack differ. Test on real hardware and watch for sustained heat or dropped frames during repeated interactions.

Public transport also creates abrupt connectivity changes: a phone may pass through a section with limited coverage and regain it moments later. With requestAnimationFrame, background callbacks pause and resume while elapsed-time calculations jump to the correct state. Avoid relying on network acknowledgements to finish a visual transition, and design the offline state to match the final state.

Compare the available animation methods

CSS transitions are usually the shortest path for a simple change between two known states. The Web Animations API adds playback controls and useful event callbacks. requestAnimationFrame is more appropriate when motion depends on live values, custom velocity, changing targets, or a shared state model.

Choose the least complex method that satisfies the interaction. The comparison below is a practical guide rather than a universal ranking; each approach can be valid within a larger design system.

Approach Best suited to Main strength Main constraint
CSS transition Simple changes between known states Declarative and easy to maintain Limited control over changing targets
Web Animations API Timelines with playback and cancellation Strong lifecycle and event controls Dynamic sequences still require coordination
requestAnimationFrame Custom springs, live values, and shared state Complete control over each frame Requires manual timing, easing, and cleanup
Animation library Complex sequences and reusable presets Consistent abstractions and features Extra dependency and bundle weight

Test and release with confidence

Build a small test page before integrating the animation into a large interface. Include the real SVG, its surrounding layout, and representative text. Use browser developer tools to record the transition, check for long tasks, and confirm that the final attributes match the intended state.

Functional checks

  • Reverse direction midway and confirm there is no jump.
  • Click or tap twice and verify that only one active loop remains.
  • Resize the container and ensure the icon remains centred.
  • Enable reduced motion and confirm that the transition resolves correctly.

Performance checks

  • Record a 60-hertz and high-refresh mobile session.
  • Inspect the console for repeated geometry or layout warnings.
  • Check CPU use while the SVG animates beside live data.
  • Test after a tab has been backgrounded for several minutes.

When Australian fintech, retail, and logistics teams in Brisbane, Adelaide, and Perth localise labels, they commonly use Australian English, 24-hour times, Australian dollar values, and day-first dates. Verify that those strings fit the layout and that motion never obscures changing information; animation should clarify hierarchy rather than delay essential content.

Open one production SVG today, add the frame-based transition, test it on a desktop browser and a phone, and ship it only when it reaches the correct state quickly, reads clearly, and remains smooth under real Australian mobile use.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames