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

create-transition

v0.4.1

Published

Create transitions that CSS can't.

Downloads

24

Readme

create-transition

Create transition animations that CSS can't.

Demo

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

Usage

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>create-transition</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <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;
    }

    .box {
      margin-top: 2000px;
      width: 200px;
      height: 200px;
      background: #FF2F92;
    }
    </style>
  </head>

  <body>
    <div class="fixed">
      <p><input type="text" id="num" value="0"></p>
      <button id="scrollToTop">scroll to top</button>
      <button id="scrollToBottom">scroll to bottom</button>
      <button id="scrollToBox">scroll to box</button>
      <button id="inc">increase</button>
      <button id="dec">decrease</button>
    </div>

    <div class="box"></div>

    <script type="module">
    import { createTransition, easeInOutQuad, easeInOutCubic } from 'https://unpkg.com/create-transition'

    document.getElementById('scrollToTop').addEventListener('click', scrollToTop)
    document.getElementById('scrollToBottom').addEventListener('click', scrollToBottom)

    document.getElementById('scrollToBox').addEventListener('click', () =>
      scrollToElement(document.querySelector('.box'), 150)
    )

    document.getElementById('inc').addEventListener('click', inc)
    document.getElementById('dec').addEventListener('click', dec)


    function scrollToElement(el, offset = 0) {
      const y = window.scrollY
      const d = el.getBoundingClientRect().top - offset
      createTransition(t => window.scrollTo(0, y + t * d), 300, easeInOutQuad)
    }

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

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

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

    function dec() {
      const num = document.getElementById('num')
      const n = parseInt(num.value) || 0
      createTransition(t => num.value = n - Math.round(100 * t), 2000, easeInOutCubic)
    }
    </script>
  </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:

  • https://gist.github.com/gre/1650294#gistcomment-1806616
  • https://github.com/CharlotteGore/functional-easing/blob/master/penner-easing.js
  • https://github.com/yuichiroharai/easeplus-velocity/blob/master/release/1.2/velocity.easeplus.js
  • https://github.com/CreateJS/TweenJS/blob/master/src/tweenjs/Ease.js

License

MIT