【发布时间】:2018-05-02 05:11:13
【问题描述】:
我这里有点问题。
如您所见,当我滚动超过 section-one div 高度的 1/3 时,我的代码触发了一个动画,其中我的 box 将 100px 从左向右移动。
如您所见,在box 中有一个line div,它从0px 增长到100px。
问题来了:我希望line 转换与我的box 元素一起触发。目前这不会发生。如果我等待的时间超过2s,即line 的animation-duration,则动画在box div 弹出屏幕时完成。
下面我附上了我的代码,这是一个link 到我的 Codepen。
翡翠
.landing-page
.section-one
.box.hidden
.line
SASS
@mixin box()
position: absolute
width: 50%
height: 50%
background: red
.landing-page
height: 100vh
width: 100vw
background: gray
.section-one
position: relative
height: 100vh
width: 50vw
background: lightblue
display: flex
justify-content: end
align-items: center
.box
@include box()
transition: 2000ms
.line
background: white
height: 20px
transition: 2000ms
animation-name: test
animation-duration: 2s
animation-fill-mode: forwards
.box.hidden
opacity: 0
transform: translateX(-100px)
@keyframes test
0%
width: 0px
100%
width: 100px
jQuery
$(document).ready(function () {
var aboutEl = $('.box'),
aboutElOffset = aboutEl.offset().top/3,
documentEl = $(document);
documentEl.on('scroll', function () {
if (documentEl.scrollTop() > aboutElOffset && aboutEl.hasClass('hidden')) aboutEl.removeClass('hidden');
});
});
【问题讨论】: