我的页面上有一个DIV #alerts_wrapper,它每5秒刷新一次,如下所示:
refresh_alerts = setInterval(function () {
$('#leftside div#alerts_wrapper').load('staffhome.php #alerts_container' );
}, 5000);
我在div上将max-height设置为200px,并滚动到auto。如果用户在此div上滚动,如何阻止div刷新?然后,如果用户停止滚动,再次开始刷新?
谢谢!
参考方案
编辑:用新代码更新,不需要滚动,只需在滚动时设置/重置标志。
DEMO
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滚动事件轮询就可以解决问题。见DEMO
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');
}
}
});
jQuery PHP在函数中传递值与实时单击? - php我正在尝试通过onclick传递一些值,这对我来说要快得多。但是我需要使用某种“实时”单击,并且正在查看.on()或.delegate()。但是,如果执行这些操作中的任何一个,则在followme()中传递这些值似乎很难。有没有我看不到的某种方法? <div class='btn btn-mini follow-btn' data-…
jquery.post()和php - php我正在使用$()。post和php来更改的内容。脚本成功执行-萤火虫清楚地表明textarea标记之间的文本已更改,并且我的小警报触发。但是,用户看不到更改。在Firefox中根本不会发生更改,而在IE中,textarea最多可延迟10秒更新。这是我正在使用的jQuery:$(document).ready(function() { $('#pv_…
PHP-服务器端验证-这是一个好方法吗? - php我已经通过jQuery的帮助进行了广泛的客户端验证。现在进入服务器端验证,如果我发现某些字段无效,是否可以简单地将错误返回给客户端并且没有任何有用的消息?我的假设是用户必须启用JavaScript才能访问我的网页。如果Web浏览器禁用了JavaScript,则用户将看不到该表单。我可以简单地使用noscript来做到这一点。如果他们通过我设计的表单提交信息,…
AJAX实时电子邮件验证(PHP) - php当用户在我的网站上创建帐户时,我希望对照我的数据库(MySQL)中的所有当前用户名检查输入的用户名,并确认是否可用。有谁知道我可以使用的任何好的库,或者是jQuery的插件? 参考方案 所需的确切信息以示例形式here给出。它使用jQuery作为JavaScript库
使用jQuery将值增加到attr - php我想增加i的值。 “ for”循环不起作用。$("a[href$='.xls']").appendTo(".xl1").attr('id','xl'+i); 我搜索所有excel文件,并将它们放在容器中并增加其id的值。谢谢吉恩 参考方案 $("a[…