Vanilla JS spring-interpolated values

Related tags

React spring
Overview

   /`\ /`\ /`\ /`\
 ~_` /_` /_` /_` /_~

       Spring

Vanilla JS spring-interpolated values.

Heavily based on https://github.com/asbjornh/tiny-spring.

Installation

npm install @superstructure.net/spring

Note: This library comes as es6 module only. If you use a transpiler like babel or swc make sure to include /node_modules/@superstructure.net/spring in your transpiler’s config.

Usage

import Spring from '@superstructure.net/spring';

// create spring
const x = new Spring(
    0, // initial value
    {
        stiffness: 40,
        damping: 5,
        mass: 2,
        precision: 100,
    }
);

// set value
x.transition(100);

// set value immediately without transition
x.set(100);

// get current value
x.get();

// subscribe to hooks
x.onUpdate((value) => {
    // ...
});

x.onRest((value) => {
    // ...
});

// clean up...
x.destroy();

By default each spring runs its own animation loop via requestAnimationFrame. If you have a lot of springs you might achieve better performance by manually implementing a single animation loop instead of using onUpdate().

// create spring
const x = new Spring(
    0,
    springConfig,
    false // IMPORTANT! Omit internal animation loop
);

function onFrame() {
    // set value
    x.transition(100);

    // update spring
    x.update();

    // do what you would otherwise do in onUpdate()
    const _x = x.get();

    requestAnimationFrame(onFrame);
}

onFrame();

Demo

Demo on Codesandbox

You might also like...

(IDW) Interpolated Heatmap Layer for mapbox-gl

(IDW) Interpolated Heatmap Layer for mapbox-gl

Mapbox :: Interpolated Heatmap(s) InterpolateHeatmapLayer is a minimalist JavaScript library for rendering temperature maps (or interpolate heatmaps)

Dec 15, 2022

Automatically persist your forms' text and select field values locally, until the form is submitted.

Garlic.js Garlic.js allows you to automatically persist your forms' text and select field values locally, until the form is submitted. This way, your

Dec 21, 2022

A basic helper to simplify relations among values, based on WeakRef

transform-once A basic helper to simplify relations among values. Optionally compatible with WeakValue too. import transformOnce from 'transform-once'

Jan 19, 2022

Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Parameter Store in bulk and output them in environment-file or json forma

Oct 18, 2022

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Oct 23, 2022

This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild).

💽 remix-esbuild-override ⚠️ While I believe you will most likely get a lot of benefit from using this library, it can sometimes destroy your product.

Dec 22, 2022

Compare 👥 and extract 🔬 differences between JSON values

json-changes Easily compare changes in JSON-like values. This can be especially useful when you want to compare an incoming payload with a counterpart

Aug 23, 2022

Tiny and fast utility to extract all possible values for a given enum.

Tiny (208B) and fast utility to extract all possible values for a given enum.

Apr 18, 2022

🚀 Transition number values using easing functions

🚀 Transition number values using easing functions

react-transition-value Transition / Animate number values using easing functions See Demos ⚡️ Getting started npm i react-transition-value import {

Dec 15, 2022

Generate deterministic fake values: The same input will always generate the same fake-output.

Generate deterministic fake values: The same input will always generate the same fake-output.

import { copycat } from '@snaplet/copycat' copycat.email('foo') // = '[email protected]' copycat.email('bar') // = 'Thurman.Schowalter668@

Dec 30, 2022

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

Dec 7, 2022

A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles

range-slider-input A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles. Ex

Dec 24, 2022

An idiomatic way to enforce values not to be null nor undefined, with first-class support for TypeScript

nullthrows An idiomatic way to enforce values not to be null or undefined, with first-class support for TypeScript. Very lightweight with no dependenc

Jul 23, 2022

JavaScript that colors the min / max values of a HTML table.

JavaScript that colors the min / max values of a HTML table.

tableMinMax Übersicht JavaScript that colors the min / max values of a HTML table. JavaScript das die Minimum / Maximum Werte, einer HTML-Tabelle einf

Feb 23, 2022

The time represented as hex color values

A clock that represents the time as hex color values I saw a project a little while ago, where I discovered that the time (in format 00:00:00) works p

Aug 16, 2022

Rotating slider for selecting numerical values.

Rotating slider for selecting numerical values. Allows mobile friendly precise selection for value from selected range with desired step. Component is especially useful for hybrid application using frameworks like Ionic, Cordova or PhoneGap.

Sep 27, 2022

Automated testing for single-page applications (SPAs). Small, portable, and easy to use. Click on things, fill in values, await for things exist, etc.

SPA Check Automated testing for single-page applications (SPAs). Small, portable, and easy to use. Click on things, fill in values, await for things e

Dec 23, 2022

Find duplicate object values of your JSON files (VSCode Extension)

Find duplicate object values of your JSON files (VSCode Extension)

JASON Lint VS Code Extension Make your life easier, use this extension to defeat the horror of duplicate values from your JSON files. Very useful when

Oct 20, 2022

✌️ A spring physics based React animation library

✌️ A spring physics based React animation library

react-spring is a spring-physics based animation library that should cover most of your UI related animation needs. It gives you tools flexible enough

Dec 28, 2022
Owner
Martin Wecke
Martin Wecke Design Code Lab
Martin Wecke
A spring that solves your animation problems.

React-Motion import {Motion, spring} from 'react-motion'; // In your render... <Motion defaultStyle={{x: 0}} style={{x: spring(10)}}> {value => <div

Cheng Lou 21.3k Jan 5, 2023
A Spring Boot - React Petshop Application

zuri-petshop A Spring Boot-React-React Native Petshop Application Installation In order to install the development environment, please follow below st

Ali Turgut Bozkurt 21 Jun 19, 2022
Smart Shop免费开源商城系统-spring cloud框架

注:该代码为1.0版本 以下介绍为v1.5部分 前言 交流群 技术微信 启山智软社区团购是一款系统稳定且经过线上反复论证并拥有大量真实用户使用的Java社区团购系统。 基于市场的反馈和变化,我们在不断开发完善社区团购的基础上,还抽离了一套属于我们自己的智慧门店物流配送系统,来帮助线下门店针对货物进行

null 356 Nov 9, 2022
NextJs + Spring Boot + MySQL

iMusic Website View Demo Description This is a website to liste to music online build with backend Spring Boot, database MySQL, and frontend Nextjs. P

 Phạm Dung Bắc 15 Nov 20, 2022
Javascript-Confirm-Dialogue - Simple Confirm Dialogue with 3 Options. Vanilla JS

Javascript Dialog Box v1.0.0 Javascript Dialog Box is a simple to use library for making dialog boxes in pure Javscript. It comes with the following f

Craig Hancock 0 Jan 12, 2022
vanilla-js lightweight custom HTML scrollbar

FakeScroll ⚡ lightweight custom-looking scrollbars 1.4KB gzipped (js) 4.0KB minified (js) 7.7KB unminified (js) ~20+ KB avarage similar scripts (unmin

Yair Even Or 353 Nov 23, 2022
Dynamic, theme-driven, style props for vanilla-extract.

Rainbow Sprinkles ?? Dynamic, theme-driven, style props for vanilla-extract. Rainbow sprinkles works similarly to @vanilla-extract/sprinkles. Like spr

Wayfair Tech 90 Dec 23, 2022
Dynamic, theme-driven, style props for vanilla-extract.

Rainbow Sprinkles ?? Dynamic, theme-driven, style props for vanilla-extract. Rainbow sprinkles works similarly to @vanilla-extract/sprinkles. Like spr

Wayfair Tech 37 May 11, 2022
Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.

@suchipi/is Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values. Usage import { is

Lily Skye 5 Sep 8, 2022
spartacus是一个基于Spring Boot 2.3.x、Spring Cloud Hoxton.SR5、Spring Security 2.3.x、OAuth2.0、Python3等开源框架构建的分布式系统

spartacus是一个基于Spring Boot 2.3.x、Spring Cloud Hoxton.SR5、Spring Security 2.3.x、OAuth2.0、Python3等开源框架构建的分布式系统,亦是一个功能完备的微服务脚手架。

xlvchao 108 Dec 24, 2022