ajax 异步刷新之后,滚屏效果已经出来,但是,滚上一段时间之后,就出现,快慢不一的现象,哪位给点建议,代码如下:
首先:滚屏代码:
function startmarquee(lh,speed,delay) {
var p=false;
var t;
var o=document.getElementById("marqueebox");
o.innerHTML+= o.innerHTML ;
o.style.marginTop=0;
o.style.color='#8E8E8E';
o.onmouseover=function(){p=true;};
o.onmouseout=function(){p=false;};
function start(){
t=setInterval(scrolling,speed);
if(!p) o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
}
function scrolling(){
if(parseInt(o.style.marginTop)%lh!=0){
o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
if(Math.abs(parseInt(o.style.marginTop))>=o.scrollHeight/2) o.style.marginTop=0;
}else{
clearInterval(t);
setTimeout(start,delay);
}
}
setTimeout(start,delay);
}
ajax请求后台,回传数据,异步刷新代码如下:
$(function() {
RollingScreen();
setInterval("RollingScreen()", 6000);
});
function RollingScreen() {
$.ajax({
url : "WelcomeServlet?action=RollingScreen",
method : "post",
dataType : 'json',
success : function(data) {
var json = data;
var options = "";
for (var int = 0; int < json.length; int++) {
options += ""+json[int].name+": "+json[int].total+"条
"
}
document.getElementById("marqueebox").innerHTML = options;
startmarquee(20,10,1000); //触发滚屏事件
},
error : function() {
alert("程序错误,请检查");
}
});
}
出现这个原因可能是:调用RollingScreen()的事件的时间和调用startmarquee(20,10,1000)事件的时间出现了叠加。哪位给看看 这个问题怎么解决??
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...