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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gsap-controller

v1.0.19

Published

A versatile GSAP controller for managing and interacting with animations.

Downloads

8

Readme

GSAP Controller

A customizable controller for managing GSAP animations in the browser.

Installation

You can install the GSAP Controller package using npm:

npm install gsap-controller

Usage

Import the GSAPController class and create an instance with your desired configurations:

import GSAPController from "gsap-controller";

// Define your GSAP animations using `gsap.to()` or `gsap.timeline()`, and give them distinct IDs for better identification:

const squareTl = gsap.timeline({ paused: true });
squareTl
  .to(".square", { x: 300 })
  .to(".square", {
    rotate: "360",
  })
  .to(".square", { scale: 1.5 }, "<");

squareTl.id = "Animation Square";

const circle = gsap.to(".circle", {
  background: "blue",
  x: 400,
  duration: 10,
});

new GSAPController({
  animations: [squareTl, circle], // pass array of tweens or timeline
  // animations: squareTl, // pass a single  tween or timeline
});

Configuration Options

  • animations: A single tween timeline or and array of tweens and timelines. Required
  • Draggable: A Draggable instance for making the controller draggable. Optional
  • position: The position of the controller (default: 'bottom center').Optional
  • theme: The theme for the controller (default: 'default').Optional
  • backgroundColor: Background color for the controller (string).Optional
  • buttonColor: Button color for the controller (string).Optional
  • textColor: Text color for the controller (string).Optional
  • width: Width of container, default 500px,(eg:"100px" or "100%"). Optional
  • disable: Default false.(boolean) Optional
  • activeAnimation: Animation id. Set default animation. Optional
  • parentSelector: Class name or Id. The controller will be appended to that element. Optional
  • onStart: Callback function that fires when the controller is instantiated. This function receives the active animation timeline as a parameter.
  • onSelectAnimationChange: Callback function that fires every time a new animation is selected. This function also receives the active animation timeline as a parameter.
new GSAPController({
  animations: [squareTl, circle],
  Draggable,
  theme: "cool",
  position: "top right",
  width: "700px",
  buttonColor: "red",
  backgroundColor: "orange",
  textColor: "blue",
  activeAnimation: "Square Animation", // Set default the animation
  parentSelector: "#parent", // Append the controller to a specific DOM ELEMENT
  onStart: (animation) => {}, // callback that fire when instantiated,
  onSelectAnimationChange: (animation) => {}, // callback that fire every time a new animation is selected
});

Select Active Animation

You can easily choose and control different animations using the select dropdown provided by the GSAP Controller. This feature allows you to manage multiple animations and control their playback seamlessly.

  1. Define your GSAP animations using gsap.to() or gsap.timeline(), and give them distinct IDs for better identification:
const squareTl = gsap.timeline({ paused: true });
squareTl
  .to(".square", { x: 300 })
  .to(".square", {
    rotate: "360",
  })
  .to(".square", { scale: 1.5 }, "<");

squareTl.id = "Square Animation"; // Customize the animation ID

const circle = gsap.to(".circle", {
  background: "blue",
  x: 400,
  duration: 10,
});

circle.id = "Circle Animation"; // Customize the animation ID

Enabling the Draggable Feature

The GSAP Controller package offers the ability to make the controller itself draggable using the GSAP Draggable plugin. This allows you to easily move the controller around the screen as needed. To enable this feature, follow these steps:

  1. First, make sure you have the necessary modules imported at the beginning of your script:
import GSAPController from "gsap-controller";
import Draggable from "gsap/Draggable.js";
import gsap from "gsap";
gsap.registerPlugin(Draggable);

const squareTl = gsap.timeline({ paused: true });
squareTl
  .to(".square", { x: 300 })
  .to(".square", {
    rotate: "360",
  })
  .to(".square", { scale: 1.5 }, "<");

const controller = new GSAPController({
  animations: squareTl,
  Draggable, // Enable the draggable feature
});
  1. Drag the container around grabbing it from the top right corner.

Positions

If you don't want to use the draggable feature you can still position the container using the following values.

  • 'top left'
  • 'top center'
  • 'top right'
  • 'center left'
  • 'center center'
  • 'center right'
  • 'bottom left'
  • 'bottom center'
  • 'bottom right'

Appending Controller to Specified Parent Element

The GSAP Controller supports appending the controller to a specified parent element using the parentSelector property. This feature provides more flexibility in where the controller is placed within the DOM.

To use this feature, follow these guidelines:

  1. Include the parentSelector property when creating a new instance of the GSAP Controller. You can pass a class name, or ID as the value.

  2. If parentSelector corresponds to a valid DOM element, the controller will be appended to that parent element. If the element is not found or the parentSelector is not provided, the controller will be appended to the body element by default.

Themes

The package provides several themes you can choose from:

  • default: A default light theme.
  • elegant: An elegant dark theme.
  • cool: A cool blue theme.
  • warm: A warm orange theme.
  • dark: A dark theme suitable for low-light environments.

License

This package is released under the MIT License.