简体   繁体   English

动画样式 CSS 到 ReactJS 样式变量

[英]Animation style CSS to ReactJS style variables

I need this CSS line:我需要这个 CSS 行:

.anim-typewriter{
     animation: typewriter 2.5s steps(25) 1s 1 normal both,
                blinkTextCursor 650ms steps(25) infinite normal;
}

To make it into a ReactJS variable style as I need to change the steps and seconds dynamically depending on the size of the text prop.为了使其成为 ReactJS 变量样式,因为我需要根据文本道具的大小动态更改步骤和秒数。

const getAnimationStyle = (duration, steps, blinkCursorDuration) => {
  // returns the css style as a js object
  return {
    animation: `typewriter ${duration}s steps(${steps}) 1s 1 normal both`,
   'blinkTextCursor' : `${blinkCursorDuration}ms steps(${steps}) infinite normal`
  };
}

// set style in element
<div style={getAnimationStyle()}></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM