【发布时间】:2019-08-26 11:37:22
【问题描述】:
我想通过滚动来控制动画, 这意味着一旦滚动达到一定数量,它就会完成动画 这意味着我不能通过暂停滚动动作来暂停动画 这是一个单一的触发器,其中先前的更改只是带有延迟的动画 我想逐渐改变与滚动页面高度百分比相对应的形状 如果页面向下滚动了 10%。正方形应该比圆形多 10% 等等 但它需要使用单个代码块发生,而不是设置多个触发器 顺滑而不突兀
我已经尝试过了,但这一切都是同时发生的。我需要用滚动来控制它。
var canSee = true;
$(window).scroll(function() {
if ($(this).scrollTop() > 60 && canSee) {
$("#square").animate({
'height': '50px',
'width': '50px',
'background-color':'#555',
'border-radius': '50%'
});
canSee = false;
} else if ($(this).scrollTop() <= 60 && !canSee) {
$("#square").animate({
'border-radius': '0%'
});
canSee = true;
}
});
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.parent{
background-color: #ccc;
height: 130vh;
padding: 20% 50%;
}
#square {
height: 50px;
width: 50px;
background-color: #555;
}
</style>
<div class="parent">
<div id="square"></div>
</div>
我希望通过滚动来控制这个布局
【问题讨论】:
标签: javascript jquery