npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

html-trajectory

v0.3.6

Published

Animate HTML elements along a curved path from their current position to a target element. Eg. a product photo flying into the cart icon.

Downloads

30

Readme

html-trajectory

html-trajectory provides lightweight HTML animations to smoothly "fly" elements from their current position to a target element — for example, animating a product image flying into a shopping cart icon.
It’s ideal for parabolic movement, curved animations, and element-to-element transitions.

disclaimer: this project was happily vibe coded at it's "best" as an experiment. I used any LLM which did the job that moment.


But why?

I had been using a simple linear flyTo function for some time in a project, based on basic CSS transform and transition to move (and scale) elements.

One day I wondered:

Can two CSS animations with different easings be combined to create real curves?

The short answer:

  • No, you cannot easily combine separate animations on the same element.
  • Yes, you can create curves by wrapping the element inside a container and animating different properties separately.
  • But — while simple curves are possible, there are limitations (still working on them :D)

So once I already had some basic functions working for linear and parabolic movements, I organized them into a small, reusable library.


Installation

npm install --save html-trajectory

or with yarn:

yarn add html-trajectory

Usage

import { flyTo } from "html-trajectory";

// Example: Fly a product image into the cart icon
flyTo('product-image', 'cart-icon');

Example HTML:

<img id="product-image" src="product.png">
<div id="cart-icon">🛒</div>

When calling flyTo('product-image', 'cart-icon'), the product image will fly straight into the cart icon.


API

flyTo(flyingId: string, targetId: string, options?: FlyOptions): void

Animates an element flying in a straight linear path to the target.

  • flyingId — ID of the element to fly (the moving projectile).
  • targetId — ID of the target element (the destination).
  • options (optional) — A configuration object:
    • moveX — Whether to move horizontally (default is true).
    • moveY — Whether to move vertically (default is true).
    • duration — Animation duration in seconds (default is 1).
    • scale — Target scale factor at the end of animation (default is 1).
    • onTransitionEnd — Callback function that executes when the animation completes (default is an empty function).
    • removeOriginal — Whether to remove the original element (default is true).
    • resetTransformation — When true, resets the clone's transform and transform-origin after cloning (default is false).
cannonBall(flyingId: string, targetId: string, options?: FlyOptions): void

Animates an element flying along a parabolic arc without rotating the element itself — similar to a cannonball.

  • flyingId — ID of the element to fly (the moving projectile).
  • targetId — ID of the target element (the destination).
  • options (optional) — A configuration object:
    • moveX — Whether to move horizontally (default is true).
    • moveY — Whether to move vertically (default is true).
    • duration — Animation duration in seconds (default is 1).
    • acceleration — Vertical acceleration in pixels/s² (default is 9.81). Higher values create a steeper arc.
    • fly3D — When true, disables acceleration to create a straight-line path instead of a parabolic arc (default is false).
    • scale — Target scale factor at the end of animation (default is 1).
    • onTransitionEnd — Callback function that executes when the animation completes (default is an empty function).
    • removeOriginal — Whether to remove the original element (default is true).
    • resetTransformation — When true, resets the clone's transform and transform-origin after cloning (default is false).
projectile(flyingId: string, targetId: string, options?: FlyOptions): void

Animates an element along a parabolic arc with rotation following the tangent of the trajectory — like a flying rocket or arrow.

  • flyingId — ID of the element to fly (the moving projectile).
  • targetId — ID of the target element (the destination).
  • options (optional) — A configuration object:
    • moveX — Whether to move horizontally (default is true).
    • moveY — Whether to move vertically (default is true).
    • duration — Animation duration in seconds (default is 1).
    • acceleration — Vertical acceleration in pixels/s² (default is 9.81). Higher values create a steeper arc.
    • scale — Target scale factor at the end of animation (default is 1).
    • onTransitionEnd — Callback function that executes when the animation completes (default is an empty function).
    • removeOriginal — Whether to remove the original element (default is true).
    • resetTransformation — When true, resets the clone's transform and transform-origin after cloning (default is false).

Testing

The library uses Vitest for testing.

npm test

Coverage

To check test coverage, run:

npm run coverage

Coverage output will appear in the coverage/ folder.


Dev Container

Use the provided docker.sh script to start a dev container with the project mounted.
(Note: the script intentionally misses the executable bit.)

bash docker.sh

License

MIT