在我的頁面上我有一定的動畫。當我滾動整個頁面時,我想確保動畫從一開始就開始,而不是在我的頁面上完成動畫。 檢查了這一點: 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
啊,我已經改變了條件的順序,我把第一部分放在第三部分,然後是第一部分。現在它的工作! –