1.2.1 • Published 3 years ago

universal-animation v1.2.1

Weekly downloads
12
License
BSD-3-Clause
Repository
github
Last release
3 years ago

universal-animation npm

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

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

支持

安装

$ npm install universal-animation --save

方法

animate(config, callback)

参数

成员类型描述必选默认值支持
config.propsArray详见下文描述✔️-
callbackfunction动画完成后触发-

config.props数组成员内容:

成员类型描述必选默认值支持
elementDOMNode|stringDOM 元素, 小程序环境为一个string 类型的标志符,详细见export()✔️-
propertystring动画属性,详见bindingx properties support✔️-
startvalue初始值-
endvalue结束值✔️-
durationnumber动画持续时间0
delaynumber动画延迟时间0
easingstring动画属性,详见bindingx easing supporteaseOutSine

export()

支持

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

参数

返回

成员类型描述
resultObject返回的对象
resultkeyArraykey 为 config.propsn.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>
    </>
  );
}
1.2.1

3 years ago

1.2.1-beta.1

3 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.1

5 years ago

0.6.6

5 years ago

0.6.5

6 years ago

0.6.0

6 years ago