我可以通過將動畫設置爲底部的div來強制滾動條向下。我也知道如何將它製作回頂部。如何將滾動條切換爲全向或全向下
但是,如果我的代碼捕捉到我通過動畫到達底部的事實,它會自動開始恢復。或者在按下之後,在到達末端時會進入無限的上下循環。
或者我應該以完全不同的方式做到這一點?
$("div").scroll(function(){
if (emergency) return;
$("span").text(x+= 1);
if (!atTop() && !atBot()){
animating = true;
sayPos("mid");
if (down)
txtbx.animate({scrollTop: txtbot}, 10, animdone);
else // up
txtbx.animate({scrollTop: 0}, 10, animdone);
} else if (atTop() && !animating) {
animating = true;
sayPos("top");
txtbx.animate({scrollTop: txtbot}, 10, animdone);
} else if (atBot() && !animating) {
animating = true;
sayPos("bot");
txtbx.animate({scrollTop: 0}, 10, animdone);
} else { // animation end: atEnd but was animating
ended = true; //animating = false;
sayPos("endAnim ----------------");
}
});
和
function animdone(){
scrlpos = txtbx.scrollTop();
if(ended){
if (down && scrlpos > 0)
txtbot = scrlpos;
ended = false;
//animating = false;
down = !down;
sayPos("..ended");
}
else sayPos("..callback");
}
function atBot(){ return scrlpos >= txtbot; }
function atTop(){ return scrlpos == 0; }