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

rax-keyframes-to-animation

v0.0.10

Published

convert keyframes code to animation, use keyframes in rax. 使用 CSS 3 中的 keyframes 语法来写 rax 动画

Downloads

10

Readme

Keyframes to Animation in Rax

在 rax 中使用 CSS3 中的 @keyframes 语法来写 rax/weex 动画。

  • 使用 keyframes 语法提供更友好的编程体验
  • weex 端使用 @weex-module/animation 执行动画
  • web 端直接使用 webView 层执行 CSS3 keyframes 动画

Demo

  • web 版

    • https://gaohaoyang.github.io/rax-keyframes-to-animation/demo/
  • weex 版(请使用具有 weex 环境的 app 扫码预览,如手淘):

    • https://gaohaoyang.github.io/rax-keyframes-to-animation/demo/bundle.min.js?_wx_tpl=https://gaohaoyang.github.io/rax-keyframes-to-animation/demo/bundle.min.js

Usage

安装组件

yarn add rax-keyframes-to-animation

npm i rax-keyframes-to-animation -S

使用示例

// App.js
import { createElement, Component, render, findDOMNode } from 'rax';
import View from 'rax-view';
import Text from 'rax-text';
import keyframesToAnimation from 'rax-keyframes-to-animation';

import './App.css';

const animationStr = `
  .element-animation{
    animation: tada linear 1s;
    animation-iteration-count: 2;
    transform-origin: 50% 50%;
  }
`;
const keyframesStr = `
  @keyframes tada{
    0% {
      transform: rotate(0deg) scale(1.00);
    }
    10% {
      transform: rotate(-3deg) scale(0.80);
    }
    20% {
      transform: rotate(-3deg) scale(0.80);
    }
    30% {
      transform: rotate(3deg) scale(1.20);
    }
    40% {
      transform: rotate(-3deg) scale(1.20);
    }
    50% {
      transform: rotate(3deg) scale(1.20);
    }
    60% {
      transform: rotate(-3deg) scale(1.20);
    }
    70% {
      transform: rotate(3deg) scale(1.20);
    }
    80% {
      transform: rotate(-3deg) scale(1.20);
    }
    90% {
      transform: rotate(3deg) scale(1.20);
    }
    100% {
      transform: rotate(0deg) scale(1.20);
    }
  }
`;

class App extends Component {

  componentDidMount = () => {
    this.runAnimation();
  }

  runAnimation = () => {
    const box = findDOMNode(this.box); // 获取元素
    // 调用动画方法
    keyframesToAnimation(box, animationStr, keyframesStr, () => {
      console.log('animation end');
    });
  }

  render() {
    return (
      <View className="container">
        <View
          ref={(ref) => {
            this.box = ref;
          }}
          className="box"
        >
          <Text className="boxText">hello</Text>
        </View>
      </View>
    );
  }
}

export default App;
/* App.css */
.container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  justify-content: flex-start;
  align-items: flex-start;
}
.box {
  width: 100;
  height: 100;
  margin-left: 160;
  margin-top: 300;
  background-color: #5c8fdb;
  border-radius: 10;
  justify-content: center;
  align-items: center;
}
.boxText {
  color: #fff;
  font-size: 30;
}

Api

keyframesToAnimation(node, animationStr, keyframesStr, callback)

功能:用于执行动画

参数:

  • node

    dom 节点

  • animationStr

    animation CSS 代码字符串,注意 animation name 要与 keyframes 中的 name 对应

  • keyframesStr

    keyframes CSS 代码字符串,注意 keyframes name 要与 animation 中的 name 对应

  • callback

    回调函数,注意当 animation-iteration-count 值为 infinite 时,回调函数永远不会执行

原理

首先将输入的 animationStr 和 keyframesStr 进行解析。

weex 中使用 @weex-module/animation 进行动画调用,使用递归的方式执行每一个关键帧的样式。

web 中直接将 keyframesStr 直接插入到样式表中,在 dom 元素上修改 animation 属性进行动画。

Contribute

开源项目,欢迎使用,欢迎找 bug,欢迎贡献代码~

https://github.com/Gaohaoyang/rax-keyframes-to-animation

yarn

Install all dependencies.

yarn run start

Runs the app in development mode.

Open http://localhost:9999 to view it in the browser.

The page will reload if you make edits.

yarn run lint

You will see the lint errors in the console.

yarn run build-demo

build demo.