0
我正在嘗試在頁面滾動上執行動畫,其中選定元素將從左向右進行動畫向下滾動,如果返回頂部,則爲所選內容設置動畫從右至左(默認位置)元素,這裏就是我試圖動畫向右滾動向下滾動並向左滾動動畫
$(document).ready(function() {
$(window).scroll(function() {
var wS = $(this).scrollTop();
if (wS <= 10) {
$("#test-box").animate({
'left': 100
}, 500);
}
if (wS > 11) {
$("#test-box").animate({
'left': $('#main-container').width() - 100
}, 500);
}
});
});
#main-container {
width: 100%;
overflow: auto;
height: 500px;
}
#test-box {
background: red;
color: #ffffff;
padding: 15px;
font-size: 18px;
position: fixed;
left: 100;
top: 10;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main-container">
<div id="test-box">test</div>
</div>
正如你所看到的,在向下滾動,測試框移動作爲我指示,但是當向上滾動,它不作爲默認去左邊,任何想法,請幫助嗎?