【发布时间】:2020-09-03 00:09:48
【问题描述】:
我已经构建了一个与此类似的动画,现在我想确保它仅在用户滚动到某个位置时才会播放,以便动画内容实际上是可见的。我如何在 React 应用程序中做到这一点?
我已尝试阅读该问题,但大多数解决方案都指向 jQuery 或 Animate.css 或 waypoint js。
- 有什么方法可以在不使用这些的情况下做到这一点?
- React 和 jQuery 如何协同工作而不引起冲突? (我问是因为我也在使用 react-bootstrap 并且他们明确声明他们已经从头开始构建它以避免将 jQuery 与 React 一起使用)我什至应该在哪里编写 jQuery 代码?
body{
font-family: Helvetica, Arial, sans-serif;
}
.container{
width: 50%;
margin: 0 auto;
}
@keyframes load{
from {
width: 0%
}
}
@-webkit-keyframes load{
from {
width: 0%
}
}
@-moz-keyframes load{
from {
width: 0%
}
}
@-o-keyframes load{
from {
width: 0%
}
}
.bar{
background-color: #EEE;
padding: 2px;
border-radius: 15px;
margin-bottom: 5px;
font-size: 14px;
color: #FFF;
font-weight: bold;
text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}
.bar::before{
content: attr(data-skill);
background-color: #f3b0ff;
display: inline-block;
padding: 5px 0 5px 10px;
border-radius: inherit;
animation: load 2s 0s;
-webkit-animation: load 2s 0s;
-moz-animation: load 2s 0s;
-o-animation: load 2s 0s;
}
.bar.front::before{
background-color: #ffcc33;
}
.bar.back::before{
background-color: #a6cfe3;
}
.bar.learning::before{
width: calc(20% - 10px);
}
.bar.basic::before{
width: calc(40% - 10px);
}
.bar.intermediate::before{
width: calc(60% - 10px);
}
.bar.advanced::before{
width: calc(80% - 10px);
}
.bar.expert::before{
width: calc(100% - 10px);
}
<div class="container">
<h1>Skill Set</h1>
<div class="bar learning" data-skill="TDD"></div>
<div class="bar back basic" data-skill="Python"></div>
<div class="bar back intermediate" data-skill="C#"></div>
<div class="bar front advanced" data-skill="CSS3"></div>
<div class="bar front expert" data-skill="HTML5"></div>
</div>
【问题讨论】:
标签: javascript jquery css reactjs css-animations