<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 100%;
height: 450px;
text-align: center;
line-height: 450px;
}
</style>
</head>
<body>
<div id="div0"></div>
<script>
var arr=[
"杨杨1","杨杨2","杨杨3","杨杨4",
"杨杨5","杨杨6","杨杨7","杨杨8",
"杨杨9","杨杨10","杨杨11","杨杨12","杨杨13",
"杨杨14","杨杨15","杨杨16","杨杨17","杨杨18",
"杨杨19","杨杨20","杨杨21","杨杨22","杨杨23",
"杨杨24","杨杨25","杨杨26","杨杨27","杨杨28",
"杨杨29","杨杨30","杨杨31","杨杨32","杨杨33",
"杨杨34","杨杨35","杨杨36","杨杨37","王雪松","杨杨38"
];
var n=0,
bool=true;
init();
function init() {
var div=document.getElementById("div0");
arr.sort(function () {
return Math.random()-0.5;
});
document.onclick=function (e) {
arr.splice((n===0 ? arr.length-1 : n-1),1);
bool=!bool;
};
setInterval(animation,200,div);
}
function animation(div) {
if(!bool)return;
div.innerHTML=arr[n];
n++;
if(n>arr.length-1)n=0;
}
</script>
</body>
</html>
setInterval(函数,时间间隔,参数)
可按照指定的周期(以毫秒计)来调用函数或计算表达式。
setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。
var num=setInterval(animation,1000,10);
function animation(n){
console.log("a",n);
}