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

aft.js

v0.3.7

Published

An Javascript Library of Animation Flow

Downloads

3

Readme

aft.js

AFT是什么

AFT是动画流(Animation Flow)开发工具库(Tools)的缩写,它可以轻松的让一个JS对象或HTML元素动起来,也可以借助时间轴的功能来管理复杂的动画设计。

浏览器支持

IE9+, Firefox, Chrome, Android Browser 4.4+, iOS Safari 7.0+.

获取代码

通过npm安装

npm install aft.js

然后在代码中引入

import * as AFT from 'aft.js';

快速上手

JS对象动画

animate(initial: object): Tween

const tween = AFT.animate({
  opacity: 0  
});

通过animate方法,可以创建一个Tween实例,并接收一个js对象为初始参数。

tween.to(result: object).duration(time: number).easing(type: string|function): Tween

tween.to({
  opacity: 1
})
.duration(1000)
.easing('ease-out') 

通过链式调用Tween实例的方法,来定义一次动画

tween.play(): Tween

通过调用play方法,来播放这次动效,并在update方法中获得每一帧变化后的值。

tween.update(current => {
  console.log(current.get('opacity'));
}).play();【

HTML元素动画

animate(initial: HTMLElement): Tween

animate方法,即可以操作一个js对象,也可以操作一个HTML元素。

AFT.animate(document.getElementById('rectangle'))
.to({
  backgroundColor: '#f00',
  rotateZ: '360deg'
})
.duration(400)
.easing('ease-in')
.iteration(2)
.direction('alternate')
.play();

当操作一个HTML元素时,to方法参数中的对象键名,必须是CSS的标准属性,且仅支持分量写法,例如:backgroundColorborderLeftColor, paddingLeft等,不支持组合写法,例如:margin,padding等。而对于transform属性的动效,可以直接写其矩阵变换方法,同样也只支持分量写法,例如:translateXrotateZ等。并且因为矩阵变换不可逆的特性,当前版本尚不支持有初始变换矩阵值的元素

继续深入

玩转复杂的动画逻辑

animate方法能快速的创建一个动画,但是对于由多个或复杂动画片段组成的完整场景就需要用到EffectAnimationTimeline三个模块。

createEffect(): Effect

通过createEffect的工厂方法可以创建一个Effect实例,并链式的调用动效方法来定义一系列动效。这些定义好的动效是可以被复用的。

const fadeInEffect = AFT.createEffect();
fadeInEffect.to({
  opacity: 1
})
.duration(400)
.easing('ease-in');

const bounceInEffect = AFT.createEffect();
bounceInEffect.to({
  translateY: '50px'
})
.duration(400)
.easing('cubic-bezier(.42,0,.5,1.5)');

createAnimation(initial: object|HTMLElement, effect: Effect, iteration: number): Animation

通过createAnimation的工厂方法创建一个Animation实例,并把js对象或HTML元素同某个动效绑定,就定义了一个动画

const rect = document.createElement('div');
rect.style.cssText = 'opacity:0;width:100px;height:100px;background-color:black;';
document.body.appendChild(rect);

const fadeIn = AFT.createAnimation(rect, fadeInEffect);
const bounceIn = AFT.createAnimation(rect, bounceInEffect);

createTimeline(): Timeline

timeline.add(animation: Animation, options: {playAt: number|function, stopAt: number|function}): Timeline

timeline.play(): Timeline

通过createTimeline的工厂方法创建一个Timeline实例,并通过实例的add方法添加一个动画以及动画播放时机的参数,就可以控制这个动画了。

让上述定义的两个动画一起播放

const timeline = AFT.createTimeline();
timeline.add(fadeIn, {
  playAt: 0
}).add(bounceIn, {
  playAt: 0
}).play();

让上述定义的两个动画顺序播放

const timeline = AFT.createTimeline();
timeline.add(fadeIn, {
  playAt: 0
}).add(bounceIn, {
  playAt: () => fadeIn.finished
}).play();

关于开源

目前aft.js仅以npm包的形式供下载和开发,未来考虑以源代码的形式在github开源。

Apache 2.0 License. © 2018.