JS实现跑马灯效果

algorain

JS实现跑马灯效果

上课无聊,没事写一个玩一玩,使用红黄绿三种也是切换,用js写一个颜色判断的函数,再用setInterval('color()',100);调用函数,100为0.1秒,下面是代码,想要看效果的戳这里www.rain1024.com-js77

下面是代码

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<style>
.content{
background-color: red;
width: 200px;
height: 200px;
margin: auto;
margin-left: 50px;
color: chartreuse;
float:left;
}
.content2{
background-color: red;
width: 200px;
height: 200px;
margin: auto;
color: chartreuse;
}
.figure{
width: 800px;
height: 100px;
/*background-color: #FFFFFF;*/
}
.all{
width: 900px;
height: 200px;
margin: auto;
}
</style>
<script>
// 设置每秒刷新一次
function myshuaxing() {
window.location.reload();
}
// setTimeout('fun()',2000);
setInterval('color()',100);
// setInterval('color_out()',1000);
// setTimeout('color_out()',1000);
</script>
<script type="text/javascript">
// setTimeout('color_over()',2000);
// setTimeout('color_out()',2000);
// alert('123');
function fun(value){
var value = prompt('324');
if(value==1){
document.getElementById('state').innerHTML = 'true';
}else{
document.getElementById('state').innerHTML = 'false';
}
}
function color(){
var show = document.getElementById('show').innerText;
var sum = document.getElementById('number').innerText;
if(show==1){
var value = document.getElementById('content');
// alert(value.style.backgroundColor);
value.style.backgroundColor='red';
document.getElementById('show').innerText = 2;
var value = document.getElementById('content2');
value.style.backgroundColor = '#FFFFFF';
var value = document.getElementById('content3');
value.style.backgroundColor = '#FFFFFF';
}else if(show==2){
var value = document.getElementById('content2');
// alert(value.style.backgroundColor);
value.style.backgroundColor='yellow';
document.getElementById('show').innerText = 3;
var value = document.getElementById('content');
value.style.backgroundColor = '#FFFFFF';
var value = document.getElementById('content3');
value.style.backgroundColor = '#FFFFFF';
}else{
var value = document.getElementById('content3');
// alert(value.style.backgroundColor);
value.style.backgroundColor='chartreuse';
document.getElementById('show').innerText = 1;
var value = document.getElementById('content');
value.style.backgroundColor = '#FFFFFF';
var value = document.getElementById('content2');
value.style.backgroundColor = '#FFFFFF';
}
sum = parseInt(sum);
sum = sum + 1;
document.getElementById('number').innerText = sum;
}
function color_over(){
// document.getElementById('state').innerHTML = 'true';
var value = document.getElementById('content');
value.style.backgroundColor="blue";
}
function color_out(){
// document.getElementById('state').innerHTML = 'true';
var value = document.getElementById('content');
value.style.backgroundColor="red";
}
function counter(){
var value1 = document.getElementById('value1').value;
var value2 = document.getElementById('value2').value;
var fig = document.getElementById('fig').value;
var result = 0;
value1 = parseFloat(value1);
value2 = parseFloat(value2);
if(fig==1){ //+
result = value1 + value2;
}else if(fig==2){ //-
result = value1 - value2;
}else if(fig==3){ //*
result = value1 * value2;
}else if(fig==4){ // /
result = value1 / value2;
}
document.getElementById('result').value = result;
}
</script>
<div align="center">
<label id="show" style="display: none">1</label>
已刷新次数:<label id="number" >0</label>
<label id="state" style="color: red;font-size: 30px;"></label></div>
<br><br><br><br>
<div class="all">
<div class="content" id="content" onmouseover="color_over();" onmouseout="color_out();">
</div>
<div class="content" id="content2" onmouseover="color_over();" onmouseout="color_out();">
</div>
<div class="content" id="content3" onmouseover="color_over();" onmouseout="color_out();">
</div>
</div>
<br><br><br><br><br>
</body>
</html>

  • Title: JS实现跑马灯效果
  • Author: algorain
  • Created at: 2017-04-30 15:34:59
  • Updated at: 2023-05-14 21:39:50
  • Link: http://www.rain1024.com/2017/04/30/js-article77/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments