•
延时嵌套会造成堆栈溢出
•
取消延时都需要句柄
var timeoutHandle = null;
function delayPlay(id, code, videoName) {
// setTimeout("javascript:closeMp();mp = new OVT_media();jQuery('#dataList .item').removeClass('yellowColor');jQuery('#itemBg" + id + "').addClass('yellowColor');" +
// "cur_code='" + code + "';codeArr=[];codeArr.push('" + code + "');getPlayUrl();" +
// "jQuery('#video-box').hide();upgdlog('" + videoName + "','" + code + "');yellowId='itemBg" + id + "'", 1000);
if (firstIn) {
playFastVideo(id, code, videoName);
firstIn = false;
} else {
clearTimeout(timeoutHandle);
//调用延时,参数写外面
timeoutHandle = setTimeout(playFastVideo, 1000, id, code, videoName);
}
}
function playFastVideo(id, code, videoName) {
closeMp();
mp = new OVT_media();
jQuery('#dataList .item').removeClass('yellowColor');
jQuery('#itemBg' + id).addClass('yellowColor');
cur_code = code;
codeArr = [];
codeArr.push(code);
getPlayUrl();
jQuery('#video-box').hide();
upgdlog(videoName, code);
yellowId = 'itemBg' + id
}
间隔
setInterval("disptime() ", 1000 ) 每间隔1秒执行一次 clearInterval(返回的id)
https://www.jb51.cc/html5/168480.html
var timer = setInterval(function() {
var current = str.substr(progress, 1);
if (current == '<') {
progress = str.indexOf('>', progress) + 1;
} else {
progress++;
}
$ele.innerHTML = str.substring(0, progress) + (progress & 1 ? '_' : '');
if (progress >= str.length) {
clearInterval(timer);
}
}, 75);
评论区