Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Auto Color</title>
- </head>
- <body id="myBody" style="background-color: #000000">
- <h1 style="text-align: center;">
- HELLO WORLD
- </h1>
- <img style="float: middle;" src="gif/giphy3.gif">
- </body>
- <script type="text/javascript">
- var r=0;
- var g=0;
- var b=0;
- rpos = true;
- gpos = true;
- bpos = true;
- window.setInterval(function(){
- changeColor();
- }, 25);
- function changeColor() {
- document.getElementById("myBody").style.backgroundColor = "rgb("+r+", "+g+", "+b+")";
- if (rpos) {
- r = r + 1;
- if (r > 255){
- r = r - 1;
- rpos = false;
- }
- } else {
- r = r - 1;
- if (r < 0) {
- r = r + 1;
- rpos = true;
- }
- }
- if (gpos) {
- g = g + 2;
- if (g > 255){
- g = g - 2;
- gpos = false;
- }
- } else {
- g = g - 2;
- if (g < 0) {
- g = g + 2;
- gpos = true;
- }
- }
- if (bpos) {
- b = b + 3;
- if (b > 255){
- b = b - 3;
- bpos = false;
- }
- } else {
- b = b - 3;
- if (b < 0) {
- b = b + 3;
- bpos = true;
- }
- }
- }
- </script>
- </html>
Add Comment
Please, Sign In to add comment