|
| 1 | +<!-- Hi this is simple digital clock with glowing effect made with a little css and js --> |
| 2 | + |
| 3 | + |
| 4 | +<!DOCTYPE html> |
| 5 | +<html lang="en" dir="ltr"> |
| 6 | + |
| 7 | +<head> |
| 8 | + <meta charset="utf-8"> |
| 9 | + <title>Digital Clock</title> |
| 10 | + <link rel="stylesheet" href="css/style.css"> |
| 11 | +</head> |
| 12 | + |
| 13 | +<body class="dark-theme || light-theme"> |
| 14 | + |
| 15 | + <canvas id="canvas"></canvas> |
| 16 | + <div class="center"> |
| 17 | + <button class=" btn-toggle">Toggle Dark Mode</button> |
| 18 | + |
| 19 | + <div class="wrapper"> |
| 20 | + <div class="display"> |
| 21 | + <div class="timezone"> |
| 22 | + <select name="TimeZone" id="TimeZone"> |
| 23 | + |
| 24 | + </select> |
| 25 | + </div> |
| 26 | + <div id="time"></div> |
| 27 | + </div> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + |
| 31 | + main |
| 32 | + <script src="script.js"></script> |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + <script> |
| 37 | + |
| 38 | + // Select the button |
| 39 | + const btn = document.querySelector('.btn-toggle'); |
| 40 | + |
| 41 | +// Listen for a click on the button |
| 42 | +btn.addEventListener('click', function() { |
| 43 | + // Then toggle (add/remove) the .dark-theme class to the body |
| 44 | + document.body.classList.toggle('dark-theme'); |
| 45 | +}) |
| 46 | + |
| 47 | + |
| 48 | + console.log("Hello World"); |
| 49 | + |
| 50 | + var canvas = document.getElementById("canvas"); |
| 51 | + var c = canvas.getContext("2d"); |
| 52 | + var tx = window.innerWidth; |
| 53 | + var ty = window.innerHeight; |
| 54 | + canvas.width = tx; |
| 55 | + canvas.height = ty; |
| 56 | + //c.lineWidth= 5; |
| 57 | + //c.globalAlpha = 0.5; |
| 58 | + |
| 59 | + var mousex = 0; |
| 60 | + var mousey = 0; |
| 61 | + |
| 62 | + addEventListener("mousemove", function() { |
| 63 | + mousex = event.clientX; |
| 64 | + mousey = event.clientY; |
| 65 | + }); |
| 66 | + |
| 67 | + |
| 68 | + var grav = 0.99; |
| 69 | + c.strokeWidth=5; |
| 70 | + function randomColor() { |
| 71 | + return ( |
| 72 | + "rgba(" + |
| 73 | + Math.round(Math.random() * 250) + |
| 74 | + "," + |
| 75 | + Math.round(Math.random() * 250) + |
| 76 | + "," + |
| 77 | + Math.round(Math.random() * 250) + |
| 78 | + "," + |
| 79 | + Math.ceil(Math.random() * 10) / 10 + |
| 80 | + ")" |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + function Ball() { |
| 85 | + this.color = randomColor(); |
| 86 | + this.radius = Math.random() * 20 + 14; |
| 87 | + this.startradius = this.radius; |
| 88 | + this.x = Math.random() * (tx - this.radius * 2) + this.radius; |
| 89 | + this.y = Math.random() * (ty - this.radius); |
| 90 | + this.dy = Math.random() * 2; |
| 91 | + this.dx = Math.round((Math.random() - 0.5) * 10); |
| 92 | + this.vel = Math.random() /5; |
| 93 | + this.update = function() { |
| 94 | + c.beginPath(); |
| 95 | + c.arc(this.x, this.y, this.radius, 0, 2 * Math.PI); |
| 96 | + c.fillStyle = this.color; |
| 97 | + c.fill(); |
| 98 | + //c.stroke(); |
| 99 | + }; |
| 100 | + } |
| 101 | + |
| 102 | + var bal = []; |
| 103 | + for (var i=0; i<50; i++){ |
| 104 | + bal.push(new Ball()); |
| 105 | + } |
| 106 | + |
| 107 | + function animate() { |
| 108 | + if (tx != window.innerWidth || ty != window.innerHeight) { |
| 109 | + tx = window.innerWidth; |
| 110 | + ty = window.innerHeight; |
| 111 | + canvas.width = tx; |
| 112 | + canvas.height = ty; |
| 113 | + } |
| 114 | + requestAnimationFrame(animate); |
| 115 | + c.clearRect(0, 0, tx, ty); |
| 116 | + for (var i = 0; i < bal.length; i++) { |
| 117 | + bal[i].update(); |
| 118 | + bal[i].y += bal[i].dy; |
| 119 | + bal[i].x += bal[i].dx; |
| 120 | + if (bal[i].y + bal[i].radius >= ty) { |
| 121 | + bal[i].dy = -bal[i].dy * grav; |
| 122 | + } else { |
| 123 | + bal[i].dy += bal[i].vel; |
| 124 | + } |
| 125 | + if(bal[i].x + bal[i].radius > tx || bal[i].x - bal[i].radius < 0){ |
| 126 | + bal[i].dx = -bal[i].dx; |
| 127 | + } |
| 128 | + if(mousex > bal[i].x - 20 && |
| 129 | + mousex < bal[i].x + 20 && |
| 130 | + mousey > bal[i].y -50 && |
| 131 | + mousey < bal[i].y +50 && |
| 132 | + bal[i].radius < 70){ |
| 133 | + //bal[i].x += +1; |
| 134 | + bal[i].radius +=5; |
| 135 | + } else { |
| 136 | + if(bal[i].radius > bal[i].startradius){ |
| 137 | + bal[i].radius += -5; |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + //forloop end |
| 142 | + } |
| 143 | + //animation end |
| 144 | + } |
| 145 | + |
| 146 | + animate(); |
| 147 | + |
| 148 | + setInterval(function() { |
| 149 | + bal.push(new Ball()); |
| 150 | + bal.splice(0, 1); |
| 151 | + }, 400); |
| 152 | + |
| 153 | + |
| 154 | + </script> |
| 155 | + |
| 156 | +</body> |
| 157 | + |
| 158 | +</html> |
0 commit comments