我创建了一个向下滚动的人,他使用2个按钮,一个按钮启动,另一个按钮停止。但如果我多次按下开始,它不会停止。另外我能做些什么来阻止当到达div /页面的结尾?向下滚动(javascript)
HTML
<div data-role="main" class="ui-content">
<!--εδώ γράφω-->
<div class="btn-group" style="width:100%">
<button onclick="start_scroll_down()" class="ui-btn ui-btn-inline ui-shadow" style="width:46%" style="position:fixed;">Start SD</button>
<button onclick="stop_scroll_down()" class="ui-btn ui-btn-inline ui-shadow" style="width:46%" style="position:fixed;">Stop SD</button>
</div>
<div class="article">
<center>
<!--text-->
</center>
</div>
</div>
的Javascript
function start_scroll_down() {
scroll = setInterval(function() {
window.scrollBy(0, 1);
console.log('Ξεκίνα');
}, 150);
}
function stop_scroll_down() {
clearInterval(scroll);
console.log('Σταμάτα');
}
就叫'stop_scroll_down()'在我认为'start_scroll_down' –
您需要跟踪的位置,如果达到了一定的高度,则stop_scroll_down(第一线)调用。 –
附注:不要使用'