说明
小于 1 分钟
说明
考虑到 项目实际使用中,数据是活的,随时会变更,所以初始化好后,需要调用 updateRoll 清除上一次前一次的定时器
var myslideup;
$(document).ready(function() {
myslideup = $(".myslideup").slideUp();
getData();// 初始化 派单轮播 也即 右下角 消息通知
});
var testArr=[[121212,2222222222,44444444444,6666666666,7777777777],[12345,2345,4567,98765,8765],[1,2,3,4],[12,34,56,78,89],[1212345]]
function getData() {
var indexx = Math.floor(Math.random() * 4);
var htmlStr = "";
jQuery.each(testArr[indexx], function (index, item) {
htmlStr+=`<li>${item}!</li>`;
});
$("#myslideup").empty();
$("#myslideup").append(htmlStr);
$(".myslideup").updateRoll(myslideup);/////////////// 改良的方法
initPdCarousel();
}
// 模拟定时取数据
var pdCarouselTimer;// 定时 查询 数据库 更新 最新派单数据
function initPdCarousel() {
clearTimeout(pdCarouselTimer);// 防止多次调用 定时器
pdCarouselTimer = setTimeout(function () {
console.log("派单通知定时器");
getData();
}, 30000);
}