Unsplashed background img 1
CodeForest - jQuery Clock

jQuery - Clock

Main Objective

The objective will be to demonstrate basic knowledge of HTML, CSS, and jQuery to create your own MadLib game!.

Prerequisites

You will need to know some basic HTML, CSS, and jQuery methods for this course.

Sub Objective

We will be going over the following tags in this tutorial:
  • HTML source code for the clock
  • CSS source code for the clock
  • jQuery source code for the clock
  • Adding your own styles!

Example

Part 1 - HTML

Here we need to place the HTML code to tell it where to generate the story and what elements to use to do so.

Example:

<div class="clock">
  <div id="clockDisplay"></div>
</div>

Part 2 - CSS

The CSS section is fairly simple to manipulate to your liking.

Example:

		#clockDisplay{ background-color: rgba(0,0,0,0.70);
					   width: 350px;
					   border-radius: 50px;
					   padding: 5px;
					   height: 50px;
					   margin: 0 auto; }
		.clock{ background-image: url(snow.gif);
				width: 400px;
				border: 10px solid white;
				height: 220px;
				padding-top: 180px;
				box-shadow: 0px 0px 50px violet;
				text-align: center;
				border-radius: 400px;
				text-shadow: 2px 2px 35px violet;
				font-size: 45px;
				font-family: 'Josefin Sans', sans-serif;
				color: white;
				margin: 0 auto; }
  

Part 3 - jQuery

For the jQuery part we'll need access to the newest jQuery library. Luckily all you have to do is take this tag from right below
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
and throw it into your header or footer!

Example:

 function renderTime(){
	 var currentTime = new Date();
	 var diem = "AM";
	 var h = currentTime.getHours();
	 var m = currentTime.getMinutes();
	 var s = currentTime.getSeconds();

	 setTimeout('renderTime()',1000);
	 	if (h == 0) {
			h = 12;
		}else if (h > 12){
			h = h - 12;
			diem = "PM";
		}
		if (h < 10){
			h = "0" + h;
		}
		if (m < 10){
			m = "0" + m;
		}
		if (s < 10){
			s = "0" + s;
		}
	var clock = document.getElementById('clockDisplay');
		clock.textContent = h + ":" + m + ":" + s + " " + diem;
		clock.innerText = h + ":" + m + ":" + s + " " + diem;
 }
 renderTime();

Now test your new undertanding here with the codepen!

Here you can try plugging in your own styles to practice before you place it into your own site
You can click back and forth between the HTML, CSS, and jQuery tabs to see all the working components or click in the top right corner to enlarge the pen for a better look.

See the Pen clock by Alex Coy (@CoyFish) on CodePen.