产品售卖进度条

// 产品售卖进度条:80%开始,每30秒一跳(+1%),到98%,停止进度,总进度18%,总共走540秒,定时器,一秒钟变化一次,时间累加到540秒时,停止定时器,进度98%;

var start=80,end=98,interval=end-start,speed=30,totalTime=interval*speed,intervalSpeed=speed*1000,htmlProgress;

function progress(inter){

inter=Math.ceil(inter/speed);

var timeInterval=setInterval(function(){

if(inter < 0){

clearInterval(timeInterval);

timeInterval=null;

}else{

htmlProgress=(totalTime/speed-inter)+start;

$("#progress").html(htmlProgress+"%");

$('#progress').width(htmlProgress+"%");

}

inter--;

},intervalSpeed)

}

function get(){

if(window.localStorage){

var now=parseInt(new Date().getTime())/1000;

var localTime=localStorage.getItem("localTime");

if(localTime != null){

if(localTime<now){// 时间超过540s,进度停止

$("#progress").html("98%");

$('#progress').width("98%");

}else if(localTime>now){// 时间没超过540s,进度继续

var inter=parseInt(localTime-now);

progress(inter)

}

}else{// 检测不到本地存储有localTime,要本地存储赋值,localTime=parseInt(new Date().getTime()/1000)+540

progress(totalTime)

localStorage.setItem("localTime",parseInt(new Date().getTime()/1000)+totalTime);

}

}

}

get();

猜你喜欢

转载自blog.csdn.net/qq_40101922/article/details/80973584