Skip to content

Commit 3e26eb5

Browse files
committedDec 10, 2019
first commit
0 parents  commit 3e26eb5

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
 

Diff for: ‎custom.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// jquery file
2+
3+
4+
$(document).ready(function(){
5+
6+
// catch body
7+
var body = $('body');
8+
9+
// now make a array of your color
10+
// add more color
11+
var color = [
12+
'red',
13+
'green',
14+
'blue',
15+
'yellow',
16+
'#00bcd4',
17+
'#e91e63',
18+
'#FF9801',
19+
'#ff5722',
20+
'rgb(58, 94, 105)'
21+
];
22+
23+
24+
25+
26+
var i = 0;
27+
28+
// make a function
29+
function changeColor(){
30+
// add css to body
31+
body.css('background',color[i]);
32+
// change value of i
33+
i++;
34+
35+
if(i>=color.length){
36+
i=0;
37+
}
38+
}
39+
// call function
40+
//changeColor();
41+
// now change the value of `i` and call function
42+
43+
setInterval(changeColor,1000);
44+
// call function every 1s
45+
46+
47+
48+
49+
})

Diff for: ‎index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Auto color change | javascript | jquery </title>
6+
<!-- main css file -->
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
11+
12+
13+
<!-- jquery cdn -->
14+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
15+
<!-- main script file / jquery file -->
16+
<script src="custom.js"></script>
17+
</body>
18+
</html>

Diff for: ‎style.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body{
2+
margin: 0px;
3+
padding: 0px;
4+
transition: 1.1s;
5+
}

0 commit comments

Comments
 (0)
Please sign in to comment.