在我的页面上我有一定的动画。当我滚动整个页面时,我想确保动画从一开始就开始,而不是在我的页面上完成动画。 检查了这一点: http://jsfiddle.net/ykto7uu9/49/从滚动到另一个元素后从头开始动画
$(document).ready(function(){
$("button").click(function(){
$("#animation").animate({left: '250px'});
});
});
html,body {
height: 100%;
}
.first {
background-color: green;
height: 100%;
width: 100%;
}
.second {
background-color: yellow;
height: 100%;
width: 100%;
}
.third {
background-color: red;
height: 100%;
width: 100%;
}
.button {
position: absolute;
margin-top: 50%;
}
.animation {
background:#98bf21;
height:100px;
width:100px;
position:absolute;
margin-top: 20%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="first" class="first"></div>
<div id="second" class="second">
<button id="button" class="button">Start Animation</button>
Click on the button Start Animation!<br>
Now every time I scroll up to green or red div, I want Block to be placed at the first position before animation.
<div id="animation" class="animation">Block</div>
</div>
<div id="third" class="third"></div>
这真的在一个例子中有效。不过,我正在处理真正的页面问题。此条件不可识别:if($(document).scrollTop()<$('#section-one')。offset()。top || $(document).scrollTop()== $('#section- 3')。偏移()。顶部)。任何想法呢? –
你也许应该用$(window)去代替,或者展示你真实的代码。你会得到什么样的错误? – Zorken17
啊,我已经改变了条件的顺序,我把第一部分放在第三部分,然后是第一部分。现在它的工作! –