clearTimeout()
// JavaScript Document
var t1,t2,t3;
//闪烁函数
function flush()
{
intrvl=0;
var title=document.getElementById('title');
for(nTimes=0;nTimes<100;nTimes++)
{
intrvl += 200;
t1=setTimeout("title.style.background='pink';",intrvl);
intrvl += 200;
t2=setTimeout("title.style.background='blue';",intrvl);
intrvl +=200;
t3=setTimeout("title.style.background='yellow'",intrvl);
}
}
//实现关闭色彩变化
//抽奖类
var data=['相机','手机','打印机','谢谢参与','购物券'],
timer=null,
flag=0;//记录键盘的次数
window.onload=function(){
var plays=document.getElementById('play'),
stops=document.getElementById('stop');
//开始抽奖
plays.onclick=playFun;
stops.onclick=stopFun;
//键盘事件
document.onkeyup=function(event){
event=event||window.event;
if(event.keyCode==13){
if(flag==0){
playFun();
flush();
flag=1;
}else{
stopFun();
stopflush();
flag=0;
}
}
}
}
function playFun(){
var that=this;
var title=document.getElementById('title'),
playsStyle=document.getElementById('play');
clearInterval(timer);
timer=setInterval(function(){
var randoms=Math.floor(Math.random()*data.length);
title.innerHTML=data[randoms];},80);
playsStyle.style.background="#999";
flush();
}
function stopFun(){
clearInterval(timer);
var plays=document.getElementById('play');
plays.style.background='pink';
}
潭州学子-1958 2016-04-06 17:50:37
大神们,请问这里要实现关闭色彩变化,应该如何做?
潭州学子-1958 2016-04-06 17:51:38
我用写了一个stopFlush(){clearTimeout(t1)...t2..t3;}关闭不了