Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

universal-animation

Package Overview
Dependencies
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-animation

A universal animation API.

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by266.67%
Maintainers
5
Weekly downloads
 
Created
Source

universal-animation npm

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

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

支持

browser weex miniApp wechatMiniprogram bytedanceMicroApp quickApp

安装

$ npm install universal-animation --save

方法

animate(config, callback)

参数
成员类型描述必选默认值支持
config.propsArray详见下文描述✔️-browser weex miniApp wechatMiniprogram bytedanceMicroApp quickApp
callbackfunction动画完成后触发-browser weex

config.props数组成员内容:

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

export()

支持

miniApp wechatMiniprogram bytedanceMicroApp quickApp

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

参数

返回
成员类型描述
resultObject返回的对象
result[key]Arraykey 为 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>
    </>
  );
}

Keywords

FAQs

Package last updated on 08 Sep 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc