我可以通过将动画设置为底部的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; }