The example in this article describes how JS implements ajax timing collection of information and scrolling display based on MSClass and setInterval. Share it with everyone for your reference, the details are as follows:
setTimeout is used for delayer and is only executed once.
setInterval: used for multiple executions.
The jquery.timers-1.2.js timer is referenced in the project, and MSClass performs regular information scrolling. It is executed every 3 minutes for about three times. The number of scrolling is getting faster and faster. The reason is that both timers and MSClass are used. setInterval,
A setInterval will be added again, and finally several setIntervals will be executed concurrently, so it is very fast. You need to clearInterval the last setInterval when calling, or quote the original method of the MSClass author.
//定时器先执行 销毁实例 var Marquee1 = new Marquee(["div1", "Content"]) function Marquee_everyTime() { Marquee1.Destroy(); //销毁实例应用 GetMarqueeInfo(); //然后ajax采集需要的信息数据。 } //ajax方法 function GetMarqueeInfo() { LG.ajax({ type: 'AjaxOther', method: 'GetMarqueeInfo', success: function (data, tipsContent) { $("#Content").html(""); $("#Content").html(tipsContent); //大容器| 小容器 |滚动的方向 |滚动的速度 | 大容器的宽度 | 大容器的高度 | 滚动休息时间 | 滚动休息时间 | 滚动结束时间 Marquee1.Direction = 2; Marquee1.Step = 0.4; Marquee1.Width = 640; Marquee1.Height = 30; Marquee1.Timer = 20; Marquee1.DelayTime = 4000; Marquee1.WaitTime = 3000; Marquee1.ScrollStep = 320; Marquee1.Start(); }, error: function () { LG.tip('信息加载失败.'); } }); }
Readers who are interested in more JavaScript-related content can check out the special topics on this site: "Summary of ajax operation skills in JavaScript", "Summary of JavaScript switching special effects and skills", " Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation special effects and techniques", "Summary of JavaScript errors and debugging techniques", "JavaScript data structure and summary of algorithm techniques", "Summary of JavaScript traversal algorithms and techniques" and "Summary of JavaScript mathematical operation usage"
I hope this article will be helpful to everyone in JavaScript programming.