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

universal-animation

v1.2.1

Published

A universal animation API.

Downloads

36

Readme

universal-animation npm

Web 场景下推荐使用 css3 ,小程序场景建议使用 createAnimation

实现动画,通过 weex-bindingx 环境允许的前提下优先使用 bindingx,不满足环境要求则使用 universal-transition 调用Weex或浏览器或小程序提供的动画API实现。

支持

安装

$ npm install universal-animation --save

方法

animate(config, callback)

参数

| 成员 | 类型 | 描述 | 必选 |默认值 | 支持 | | --- | --- | --- | --- | --- | --- | | config.props | Array | 详见下文描述 | ✔️ | - | | | callback | function | 动画完成后触发 | ✘ | - | |

config.props数组成员内容:

| 成员 | 类型 | 描述 | 必选 |默认值 | 支持 | | --- | --- | --- | --- | --- | --- | | element | DOMNode|string | DOM 元素, 小程序环境为一个string 类型的标志符,详细见export() | ✔️ | - | | | property | string | 动画属性,详见bindingx properties support | ✔️ | - | | | start | value | 初始值 |✘ | - | | | end | value | 结束值 | ✔️ | - | | | duration | number | 动画持续时间 | ✘ | 0 | | | delay | number | 动画延迟时间 |✘ | 0 | | | easing | string | 动画属性,详见bindingx easing support | ✘ | easeOutSine | |

export()

支持

因为小程序无法提供DOMNode,并且动画应用方式也有差异。所以小程序中使用该方法获取动画内容,然后手动绑定到元素。

参数

返回

| 成员 | 类型 | 描述 | | --- | --- | --- | | result | Object | 返回的对象 | | result[key] | Array | key 为 config.props[n].element,value 为小程序动画内容,将该值绑定到元素 |

示例

import { createElement, useState, useEffect, useRef, Fragment } from 'rax';
import animate from 'universal-animation';
import findDOMNode from 'rax-find-dom-node';
import View from 'rax-view';
import { isMiniApp } from 'universal-env';

export default function Demo() {
  const [animationInfo1, setAnimationInfo1] = useState({});
  const [animationInfo2, setAnimationInfo2] = useState({});
  const block1 = useRef();
  const block2 = useRef();

  useEffect(() => {
    const animationResult = animate(
      {
        props: [
          {
            element: isMiniApp ? 'view1' : findDOMNode(block1.current),
            property: 'transform.translateX',
            easing: 'easeOutSine',
            duration: 200,
            start: 0,
            end: 200,
            delay: 100,
          },
          {
            element: isMiniApp ? 'view2' : findDOMNode(block2.current),
            property: 'opacity',
            easing: 'easeOutSine',
            duration: 200,
            end: 0.2,
            delay: 100,
          },
        ],
      },
      () => {
        console.log('timing end');
      },
    ).export();

    if (isMiniApp) {
      setAnimationInfo1(animationResult.view1);
      setAnimationInfo2(animationResult.view2);
    }
  }, []);

  return (
    <>
      <View
		ref={block1}
        animation={animationInfo1}
        style={{ backgroundColor: 'red', height: '100rpx', width: '100rpx' }}
      ></View>
      <View
		ref={block2}
        animation={animationInfo2}
        style={{ backgroundColor: 'yellow', height: '100rpx', width: '100rpx' }}
      ></View>
    </>
  );
}