代码
setInterval(fun,time)函数fun以间隔time循环执行
clearInterval(timer)清除定时器
setTimeout(fun,time)函数fun在time后执行一次
下面实现一个图片滚动效果:
function Get(obj) {
return document.getElementById(obj);
}
function Marquee() {
var Slider = Get("Slider");
totalScollWidth = GetScrollWidth(scrollNum);
var moveLength = totalScollWidth + 25 +ImgSpace;
for (var i = 0; i < moveLength; i++) {
Slider.scrollLeft += 1;
}
ImgSpace = 0;
clearInterval(timer);
scrollNum++;
var timeout = setTimeout(Stop, 3000); //停3秒
if (scrollNum > GetScrollNum()) {
Slider.scrollLeft = 0;
scrollNum = 0;
}
}
function Start() {
timer = setInterval(Marquee, speed);
}
function Stop()
{
timer = setInterval(Marquee, speed);
}
clearInterval(timer)清除定时器
setTimeout(fun,time)函数fun在time后执行一次
下面实现一个图片滚动效果:
function Get(obj) {
return document.getElementById(obj);
}
function Marquee() {
var Slider = Get("Slider");
totalScollWidth = GetScrollWidth(scrollNum);
var moveLength = totalScollWidth + 25 +ImgSpace;
for (var i = 0; i < moveLength; i++) {
Slider.scrollLeft += 1;
}
ImgSpace = 0;
clearInterval(timer);
scrollNum++;
var timeout = setTimeout(Stop, 3000); //停3秒
if (scrollNum > GetScrollNum()) {
Slider.scrollLeft = 0;
scrollNum = 0;
}
}
function Start() {
timer = setInterval(Marquee, speed);
}
function Stop()
{
timer = setInterval(Marquee, speed);
}