2
此腳本在我的成員計算機上佔用了大量資源。我有其他的間隔腳本不會吃掉任何資源。我試圖延長時間,但這會減緩更新。有什麼建議麼?BIG Resource Eater
<script type="text/javascript">
$('document').ready(function(){
updatestatus();
scrollalert();
});
function updatestatus(){
//Show number of loaded items
var totalItems=$('#scontent p').length;
$('#status').text('Done');
}
function scrollalert(){
var scrolltop=$('#scrollbox').attr('scrollTop');
var scrollheight=$('#scrollbox').attr('scrollHeight');
var windowheight=$('#scrollbox').attr('clientHeight');
var scrolloffset=10;
if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
{
//fetch new items
$('#status').text('Loading more members...');
$.get('allonline.php', '', function(newitems){
$('#scontent').load('allonline.php');
updatestatus();
});
}
setTimeout('scrollalert();', 60000);
}
</script>
這可能是主要問題。其他的東西:不是一遍又一遍地調用'$(#foo')爲同一個元素,緩存在某處。另外,'setTimeout'調用應該是'setTimeout(scrollAlert,6000);' – Pointy 2010-07-23 12:54:39