Skip to content

Commit

Permalink
Merge pull request #41 from DAP2506/add-sec-function
Browse files Browse the repository at this point in the history
added a microsecond part in the code
  • Loading branch information
swapnilsparsh authored Oct 4, 2021
2 parents bc2f651 + 6192117 commit d92d402
Showing 1 changed file with 65 additions and 54 deletions.
119 changes: 65 additions & 54 deletions 02 - Clock/index.html
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock</title>
<link rel="stylesheet" href="style.css" />
<link rel="icon" href="assets/favicon.png">

</head>
<body>
<h2 class="heading">
Clock
</h2>
<div class="clock">
<div class="hour">
<div class="hr" id="hr"></div>
</div>
<div class="min">
<div class="mn" id="mn"></div>
</div>
<div class="sec">
<div class="sc" id="sc"></div>
</div>

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock</title>
<link rel="stylesheet" href="style.css" />
<link rel="icon" href="assets/favicon.png">

</head>

<body>
<h2 class="heading">
Clock
</h2>
<div class="clock">
<div class="hour">
<div class="hr" id="hr"></div>
</div>
<div class="min">
<div class="mn" id="mn"></div>
</div>



<footer>
<p>&#x3c; &#47; &#x3e; with ❤️ by
<a href="https://swapnilsparsh.github.io/">Swapnil Srivastava</a>
<br>
<a href="https://github.com/swapnilsparsh/30DaysOfJavaScript" target="_blank">#30DaysOfJavaScript
</a>
</p>
</footer>

<script type="text/javascript">
const deg = 6;
const hr = document.querySelector('#hr')
const mn = document.querySelector('#mn');
const sc = document.querySelector('#sc');

setInterval(() => {
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * deg;
let ss = day.getSeconds() * deg;

hr.style.transform = `rotateZ(${(hh) + (mm/12)}deg)`;
mn.style.transform = `rotateZ(${mm}deg)`;
sc.style.transform = `rotateZ(${ss}deg)`;
})
</script>
</body>
</html>
<div class="sec">
<div class="sc" id="sc"></div>
</div>
</div>



<footer>
<p>&#x3c; &#47; &#x3e; with ❤️ by
<a href="https://swapnilsparsh.github.io/">Swapnil Srivastava</a>
<br>
<a href="https://github.com/swapnilsparsh/30DaysOfJavaScript" target="_blank">#30DaysOfJavaScript
</a>
</p>
</footer>

<script type="text/javascript">
const deg = 6;
// getting all hands of clock from html through id
const hr = document.querySelector('#hr')
const mn = document.querySelector('#mn');
const sc = document.querySelector('#sc');

setInterval(() => {
let day = new Date();

//setting the actual seconds minutes and hour in clock

let ms = day.getMilliseconds() * deg;
let hh = day.getHours() * 30;
let mm = day.getMinutes() * deg;
let ss = day.getSeconds() * deg + ms / 1000;

//changing the degrees in the style as per the time

hr.style.transform = `rotateZ(${(hh) + (mm / 12)}deg)`;
mn.style.transform = `rotateZ(${mm}deg)`;
sc.style.transform = `rotateZ(${ss}deg)`;

}, 1);
</script>
</body>

</html>

0 comments on commit d92d402

Please sign in to comment.