javascript - 如何在 Typescript/React 中使用 Tailwind 动画增加进度条宽度
问题描述
我有一个简单的进度条组件,如下所示,我想添加动画,比如增加宽度0% to 100%
一次stepCount > 0
是真的。(即使用s.stepBarProgressed
)
<div className={s.stepBarContainer}>
<div className={s.stepBarDefault}>
<div
id="bar"
className={stepCount > 0 ? s.stepBarProgressed : s.stepBarNoProgressed}
/>
</div>
</div>
那么我的顺风css是这样的
.stepBarContainer {
@apply w-1/6 items-center content-center flex;
}
.stepBarDefault {
@apply w-auto bg-gray-300 rounded items-center align-middle flex-1;
}
.stepBarProgressed {
@apply animate-bounce;
@apply bg-teal-main text-xs leading-none py-1 text-center text-gray-600 rounded;
}
.stepBarNoProgressed {
@apply animate-bounce;
@apply bg-gray-300 text-xs leading-none py-1 text-center text-gray-600 rounded;
}
我尝试添加如下所示的 eventlistner,但它不起作用 - 我可以使用 Tailwind 或使用 Typescript 函数以任何方式本地实现此类动画吗?
const stepChange = () => {
document.addEventListener('click', function() {
let progress = 0
const intervalSpeed = 10
const incrementSpeed = 1
const bar = document.getElementById('bar')
const progressInterval = setInterval(function() {
progress += incrementSpeed
bar!.style.width = `${progress}%`
if(progress >= 100) {
clearInterval(progressInterval)
}
}, intervalSpeed)
})
}
解决方案
推荐阅读
- smartcard - PPS(协议和参数选择)命令 - 全局平台脚本
- node.js - Mocha 可以在没有测试文件的情况下执行测试吗?
- python - Pyx有一条曲线,它的曲线文字有不同的颜色
- java - Netbeans 安装程序没有看到 jdk
- javascript - 等待来自模态框的用户输入
- python - 在同一类中使用变量由另一个类python中的名称空间设置
- codenameone - 代号一个很棒,但不确定在哪里放置带有 css 和下划线的图像并且下划线不起作用
- reactjs - 悬停时VS Code不显示完整的类型信息
- php - 我想打印一个表格而不打印所有行,有没有办法做到这一点?
- twilio - 如何更改 Twilio 正在进行的呼叫“收件人”字段?(使用 JS/节点)