編集:新しいコードで更新されました。スクロールするときにフラグを設定/リセットするだけでポーリングする必要はありません。
デモ
var isScrolling = false;
$(function() {
$('#scrollingDiv').on('scroll', function() {
isScrolling = true;
});
refreshTimer = setInterval(refreshContent, 5000);
function refreshContent() {
if (!isScrolling) {
$('#scrollingDiv').prepend('Latest Content <br />');//test code
//$('#leftside div#alerts_wrapper').load('staffhome.php #alerts_container');
}
isScrolling = false;
}
});
---------- 古い投稿 ----------
div スクロール イベントの単純なポーリングでうまくいきます。デモを見る
var isScrolling = false;
var refreshTimer = null;
$(function() {
$('#scrollingDiv').on('scroll', function() {
isScrolling = true;
if (refreshTimer != null) {
clearInterval(refreshTimer);
refreshTimer = null;
}
});
//polling to see if still scrolling
var pollScrolling = setInterval(function() {
isScrolling = false;
if (refreshTimer == null) {
refreshTimer = setInterval(refreshContent, 5000);
}
}, 500);
//initialize timer
refreshTimer = setInterval(refreshContent, 5000);
function refreshContent() {
if (!isScrolling) {
$('#scrollingDiv').prepend('Latest Content <br />');
//$('#leftside div#alerts_wrapper').load('staffhome.php #alerts_container');
}
}
});