【发布时间】:2018-05-02 08:07:14
【问题描述】:
- 首先,我在使用
jquery在滚动上为这些box元素设置动画时遇到了一点问题。我希望我的animation在滚动超过section的 1/4 时启动。- 其次,我的
boxdiv 过去是垂直居中的,但在过渡期间添加@keyframes后,它们不再居中。如果您删除animation-fill-mode: forwards,您可以看到它们在转换结束时如何恢复。 - 最后一个问题.. 当我开始滚动时,可以使用
jquery为这两个框设置动画,而不必为每个sections编写不同的代码吗?我在想,如果我在我的boxdiv 中添加一些常见的类应该可以工作,对吧?
- 其次,我的
最初,在我的jquery 文件中,我尝试在box div 上设置带有opacity:0 的hidden 类,当我开始滚动时,它会变成带有opacity:1 的showing 类。 . 但这并不顺利。
在 YouTube 上找到的其他解决方案也没有帮助。将其他人的代码与我的代码混合似乎效果不佳。
如您所见,没有 jquery 代码,因为在我的大脑开始乱用它之后,它变得一团糟,有一次我认为我应该重新开始。
Here 是我的 Codepen 的链接。
翡翠
.landing-page
.section-one
.box-one
.section-two
.box-two
SASS
@mixin box()
position: absolute
width: 200px
height: 200px
background: black
.landing-page
height: 100vh
width: 100vw
background: gray
.section-one
position: relative
height: 100vh
width: 100vw
background: lightblue
.box-one
@include box()
top: 50%
right: 10%
transform: translate(-50%,-50%)
animation-name: box-one-animation
animation-duration: 2s
animation-fill-mode: forwards
.section-two
position: relative
height: 100vh
width: 100vw
background: lightgreen
.box-two
@include box()
top: 50%
left: 10%
transform: translate(-50%,-50%)
animation-name: box-two-animation
animation-duration: 2s
animation-fill-mode: forwards
@keyframes box-one-animation
0%
transform: translateX(0)
100%
transform: translateX(-50%)
@keyframes box-two-animation
0%
transform: translateX(0)
100%
transform: translateX(50%)
【问题讨论】: