Socket
Socket
Sign inDemoInstall

create-transition

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-transition

Create transitions that CSS can't.


Version published
Maintainers
1
Created

Readme

Source

create-transition

Create transition animations that CSS can't.

Usage

https://jiangfengming.github.io/create-transition/examples/

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../dist/createTransition.js"></script>
<script>
const { createTransition: transition, easeInOutQuad, easeInOutCubic } = createTransition

function gotoTop() {
  const y = window.scrollY
  transition(t => window.scrollTo(0, y - t * y), 300, easeInOutQuad)
}

function gotoBottom() {
  const y = window.scrollY
  const d = document.documentElement.scrollHeight - window.innerHeight - window.scrollY
  transition(t => window.scrollTo(0, y + t * d), 300, easeInOutQuad)
}

function inc() {
  const num = document.getElementById('num')
  const n = parseInt(num.value) || 0
  transition(t => num.value = n + Math.round(100 * t), 2000, easeInOutCubic)
}

function dec() {
  const num = document.getElementById('num')
  const n = parseInt(num.value) || 0
  transition(t => num.value = n - Math.round(100 * t), 2000, easeInOutCubic)
}
</script>
<style>
body {
  height: 9999px;
  background-image: linear-gradient(to bottom, rgba(255,255,0,0.5), rgba(0,0,255,0.5));
}

.fixed {
  position: fixed;
  top: 10px;
  left: 10px;
}
</style>
</head>
<body>
<div class="fixed">
  <p><input type="text" id="num" value="0"></p>
  <button onclick="gotoTop()">go to top</button>
  <button onclick="gotoBottom()">go to bottom</button>
  <button onclick="inc()">increase</button>
  <button onclick="dec()">decrease</button>
</div>
</body>
</html>

Import

import { createTransition, easeInOutQuad /* , ...other easing functions */} from 'create-transition'

If you don't need easing functions:

import createTransition from 'create-transition'

APIs

createTransition(animate, duration, easing = linear)

Creates a transition between two states. It uses requestAnimationFrame underneath.

Params:

animate(o)
Function. The animation function to run per frame. o is the eased value computed by easing(t).

duration
Number. The number of milliseconds a transition animation should take to complete.

easing(t)
Function. A mathematical function that describes how fast one-dimensional values change during animations. This lets you vary the animation's speed over the course of its duration. See more about easing functions: <timing-function> and Improved Easing Functions

t: Number. t = (currentTime - startTime) / duration. It represents the percentage of completeness of the transition. It's value is between 0 and 1.

The return value is the eased value of t. 0.0 represents the initial state, and 1.0 represents the final state. Depending on the specific function used, the calculated output can sometimes grow to be greater than 1.0 or smaller than 0.0 during the course of an animation. This causes the animation to go farther than the final state, and then return. For some properties, such as left or right, this creates a kind of "bouncing" effect.

Example easing function:

function easeInQuad(t) {
  return t * t
}

You can create easing functions using bezier-easing.

generateEaseInBack(amount)

Generates an easeInBack function with custom amount.

generateEaseOutBack(amount)

Generates an easeOutBack function with custom amount.

generateEaseInOutBack(amount)

Generates an easeInOutBack function with custom amount.

generateEaseInElastic(amplitude, period)

Generates an easeInElastic function with custom amplitude and period.

generateEaseOutElastic(amplitude, period)

Generates an easeOutElastic function with custom amplitude and period.

generateEaseInOutElastic(amplitude, period)

Generates an easeInOutElastic function with custom amplitude and period.

Preset easing functions

  • linear
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInBack (shortcut of generateEaseInBack(1.7))
  • easeOutBack (shortcut of generateEaseOutBack(1.7))
  • easeInOutBack (shortcut of generateEaseInOutBack(1.7 * 1.525))
  • easeInElastic (shortcut of generateEaseInElastic(1, 0.3))
  • easeOutElastic (shortcut of generateEaseOutElastic(1, 0.3))
  • easeInOutElastic (shortcut of generateEaseInOutElastic(1, 0.3 * 1.5))
  • easeInBounce
  • easeOutBounce
  • easeInOutBounce

Easing functions are collected from:

License

MIT

Keywords

FAQs

Last updated on 05 Sep 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc