效果图:
页面代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点名表</title>
<link rel="stylesheet" href="../css/index.css">
</head>
<body>
<div class="header" style="clear: both">
<div class="biaoti">
<span>随机点名</span>
</div>
<div class="getname">
</div>
<div class="begin">
<input type="button" id="start" value="开始点名">
<input type="button" id="end" value="结束点名">
</div>
<div class="names" id="dv">
<ul id="li_name">
</ul>
</div>
</div>
</body>
<script src="../js/common.js"></script>
<script>
var arr="潘石屹 | 王 石 | 蒋锡培 | 向文波 | 牛根生 | 熊晓鸽 | 王冉 | 于清教 | 谢清海 | 刘旗辉 |刘步尘 | 陈达夫 | 船长 | 叶茂中 | 李士福 | 王进生 | 任志强 | 付伟 | 孙虹钢 | 宋新宇 |王微 | 翁向东 | 周济谱 | 袁岳 | 成君忆 | 艾学蛟 | 雷永军 | 刘秋华 | 宋炜 | 刘东华 |科特勒 | 陈志列 | 张巨峰 | 姚日来 | 李朝曙 | 刘兴亮 | 沧海 | 曾玉 | 姜汝祥 | 徐浩然 | 邓国坚|辜胜阻 | 范以锦 | 郭梓林 | 秦合舫 | 王育琨 | 王辉耀 | 胡奎 | 华仔 | 韩耀国 | 唐清建 |曲向东 | 李志起 | 吴伯凡 | 景素奇 | 贾昌荣 | 林国峰 | 沈坤 | 刘贤方 | 周永亮 | 马向阳 | 辜胜阻 | 范以锦 | 郭梓林 | 秦合舫 | 王育琨 | 王辉耀 | 胡奎 | 华仔 | 韩耀国 | 唐清建 |曲向东 | 李志起 | 吴伯凡 | 景素奇 | 贾昌荣 | 林国峰 | 沈坤 | 刘贤方 | 周永亮 | 马向阳 |熊焰 | 唐崇健 | 王广伟 | 孔繁任 | 刘孝全 | 徐浩然 | 沈青 ";
var arrName=arr.split("|");
var flag=true;
var opacity=10;
var flag1=true;
for(var i=0;i<arrName.length;i++){
var setname=document.createElement("li");
setname.innerText=arrName[i];
myId("li_name").appendChild(setname);
}
var liObjs= myId("li_name").getElementsByTagName("li");
myId("start").onclick=function () {
if (flag){
b=setInterval('move()',300);
a=setInterval('checkName()',100);
c=setInterval('change()',500);
flag=false;
}
}
myId("end").onclick=function () {
flag=true;
clearInterval(a);
clearInterval(b);
clearInterval(c);
myId("dv").style.left=350+"px";
myId("dv").style.top=130+"px";
document.getElementsByClassName("names")[0].style.opacity=1;
// myId("dv").style.zIndex=1;
}
function checkName() {
var num=parseInt(Math.random()*liObjs.length);
for (var i=0;i<liObjs.length;i++){
liObjs[i].style.backgroundColor="";
liObjs[i].style.color="";
}
liObjs[num].style.backgroundColor="#f10215";
liObjs[num].style.color="black";
document.getElementsByClassName("getname")[0].innerHTML=liObjs[num].innerText;
}
function move() {
var x=parseInt(Math.random()*500+1);
var y=parseInt(Math.random()*150+1);
myId("dv").style.left=x+"px";
myId("dv").style.top=y+"px";
}
function change(){
if(flag1){
opacity--;
// if(opacity>0){
document.getElementsByClassName("names")[0].style.opacity=opacity/10;
// }
}
if(opacity==0){
flag1=false;
// opacity=10;
}
if(!flag1){
opacity++;
document.getElementsByClassName("names")[0].style.opacity=opacity/10;
}
if(opacity==10){
flag1=true;
// opacity=10;
}
}
</script>
</html>
css代码:
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
body{
background-color: pink;
}
.header{
position: relative;
}
.biaoti{
width: 200px;
height: 100px;
background-color: white;
margin: 30px auto;
border-radius: 10px;
text-align: center;
}
.biaoti span{
color: grey;
font-size: 26px;
line-height: 100px;
font-weight: inherit;
text-shadow: 2px 1px 2px #CCCCCC;
}
.getname{
width: 130px;
height: 60px;
background-color: white;
position: absolute;
top: 38px;
right: 456px;
border-radius: 8px;
line-height: 60px;
text-align: center;
color:black;
font-size: 26px;
font-family: 宋体;
font-weight: bolder;
}
.begin{
height: 300px;
width: 100px;
/*background-color: hotpink;*/
/*margin: 10px auto;*/
position: absolute;
top: 260px;
right: 233px;
}
#start,#end{
width: 100px;
height: 50px;
font-size:20px;
background-color:skyblue;
}
#start{
margin-bottom: 50px;
}
.names{
width: 800px;
height: 495px;
background-color: honeydew;
/*margin: 20px auto;*/
text-align: center;
top: 130px;
left: 350px;
position: absolute;
z-index: -1;
}
.names li{
float: left;
margin: 5px 10px;
width: 80px;
height:35px;
line-height: 35px;
background-color:greenyellow;
color: #666666;
font-size: 18px;
font-weight: normal;
border-radius: 5px;
}
JS代码:
function myId(id) {
return document.getElementById(id);
}
主要功能有:点名,随机移动,透明度的使用
学习JS练下手,疯狂百度代码,再加到自己代码里面,难受!!!