-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
75 lines (70 loc) · 1.83 KB
/
test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
<style>
body {
background: red;
}
.container{
width:322px;
margin:auto;
position: absolute;
left: 0;
right: 0;
margin-top: 40px;
}
.box {
width: 100px;
height: 100px;
/*background: coral;*/
display: inline-block;
}
.box:first-child{
background: red;
}
.box:nth-child(2){
background: yellow;
}
.box:last-child {
background: pink;
}
</style>
</head>
<body>
<div class="container">
<div id="box1" class="box" data-color="red"></div>
<div class="box" data-color="yellow"></div>
<div class="box" data-color="pink"></div>
</div>
<script src="js/jquery-1.11.3.min.js"></script>
<script>
$(function () {
var index = 0;
var timer = setInterval(function () {
var color = $('.box').eq(index).data('color');
console.log(color);
$('body').css({
background: color
});
index = (index+1)% $('.box').size();
},10);
$('.box').click(function(index){
// alert($(this).index);
// console.log(index);
// console.log($(this).index);
clearInterval(timer);
var color = $(this).data('color');
console.log(color);
$('body').css({
background: color
});
});
})
</script>
</body>
</html>