» » One great jquery digital clock demo/example

 

One great jquery digital clock demo/example

Author: bamboo06 on 8-11-2014, 15:28, views: 3035

35
In previous articles, we introduced several jquery digital clock realization with demos, they are Digital alarm clock by HTML5, Use jQuery and CSS3 to create digital clock (jquery part). If you are interested in them, you can go back to review them. Today we give you another digital clock example by jquery similar like previous one. May you like it.

Now let's go step by step.
HTML
<div id="clock" class="light">
	<div class="display">
		<div class="weekdays">
		</div>
		<div class="ampm">
		</div>
		<div class="alarm">
		</div>
		<div class="digits">
		</div>
	</div>
</div>

Main CSS Style
#clock{
	width:370px;
	padding:40px;
	margin:0px auto 60px;
	position:relative;
}

#clock:after{
	content:'';
	position:absolute;
	width:400px;
	height:20px;
	border-radius:100%;
	left:50%;
	margin-left:-200px;
	bottom:2px;
	z-index:-1;
}


#clock .display{
	text-align:center;
	padding: 40px 20px 20px;
	border-radius:6px;
	position:relative;
	height: 54px;
}

Main js
script.js
	var clock = $('#clock'),
		alarm = clock.find('.alarm'),
		ampm = clock.find('.ampm');

	// Map digits to their names (this will be an array)
	var digit_to_name = 'zero one two three four five six seven eight nine'.split(' ');

	// This object will hold the digit elements
	var digits = {};

	// Positions for the hours, minutes, and seconds
	var positions = [
		'h1', 'h2', ':', 'm1', 'm2', ':', 's1', 's2'
	];

	// Generate the digits with the needed markup,
	// and add them to the clock

	var digit_holder = clock.find('.digits');

	$.each(positions, function(){

		if(this == ':'){
			digit_holder.append('<div class="dots">');
		}
		else{

			var pos = $('<div>');

			for(var i=1; i<8; i++){
				pos.append('<span class="d' + i + '">');
			}

			// Set the digits as key:value pairs in the digits object
			digits[this] = pos;

			// Add the digit elements to the page
			digit_holder.append(pos);
		}

	});

	// Add the weekday names

	var weekday_names = 'MON TUE WED THU FRI SAT SUN'.split(' '),
		weekday_holder = clock.find('.weekdays');

	$.each(weekday_names, function(){
		weekday_holder.append('<span>' + this + '</span>');
	});

	var weekdays = clock.find('.weekdays span');


	// Run a timer every second and update the clock

	(function update_time(){

		// Use moment.js to output the current time as a string
		// hh is for the hours in 12-hour format,
		// mm - minutes, ss-seconds (all with leading zeroes),
		// d is for day of week and A is for AM/PM

		var now = moment().format("hhmmssdA");

		digits.h1.attr('class', digit_to_name[now[0]]);
		digits.h2.attr('class', digit_to_name[now[1]]);
		digits.m1.attr('class', digit_to_name[now[2]]);
		digits.m2.attr('class', digit_to_name[now[3]]);
		digits.s1.attr('class', digit_to_name[now[4]]);
		digits.s2.attr('class', digit_to_name[now[5]]);

		// The library returns Sunday as the first day of the week.
		// Stupid, I know. Lets shift all the days one position down, 
		// and make Sunday last

		var dow = now[6];
		dow--;
		
		// Sunday!
		if(dow < 0){
			// Make it last
			dow = 6;
		}

		// Mark the active day of the week
		weekdays.removeClass('active').eq(dow).addClass('active');

		// Set the am/pm text:
		ampm.text(now[7]+now[8]);

		// Schedule this function to be run again in 1 sec
		setTimeout(update_time, 1000);

	})();

	// Switch the theme

	$('a.button').click(function(){
		clock.toggleClass('light dark');
	});

});

Another js code we use plugin moment.js.
In the end include the files:
<script src="js/moment.min.js"></script>
<script src="assets/js/script.js"></script>
<link rel="stylesheet" href="assets/css/style.css" type="text/css">

Then you will see the effect we revealed at the begin. If you have any suggestions about this jquery digital clock timer, please write to us. We will improve it and make it better.

Category: Javascript

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
23 April 2017 07:07

Godin

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Thanks a lot for sharing this code with us. I was just writing essay and I was in dire need of this code and now, I have the code. You always provide me what I need most and that's why I love your work!

<
  • 0 Comments
  • 0 Articles
19 June 2017 07:56

best hiking tour oahu

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. best hiking tour oahu

<
  • 0 Comments
  • 0 Articles
8 July 2017 06:04

mobile pr release

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. mobile pr release

<
  • 0 Comments
  • 0 Articles
10 July 2017 18:28

best journalist apps

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. best journalist apps

<
  • 0 Comments
  • 0 Articles
12 July 2017 20:20

small business pr

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Good focuses you composed here..Great stuff...I think you've made some genuinely intriguing points.Keep up the great work. small business pr

<
  • 0 Comments
  • 0 Articles
16 July 2017 18:58

NJ Party Bus

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more. NJ Party Bus

<
  • 0 Comments
  • 0 Articles
21 July 2017 21:32

goevo

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
found your this post while searching for some related information on blog search...Its a good post..keep posting and update the information goevo

<
  • 0 Comments
  • 0 Articles
25 July 2017 05:41

discount designer shoes

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. discount designer shoes

<
  • 0 Comments
  • 0 Articles
27 July 2017 18:05

Party Bus NJ

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I cherish the way you compose and share your corner! Exceptionally intriguing and distinctive! Keep it coming! Party Bus NJ

<
  • 0 Comments
  • 0 Articles
29 July 2017 19:06

natural weightloss

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
A debt of gratitude is in order for your data, it was truly exceptionally helpfull.. natural weightloss

<
  • 0 Comments
  • 0 Articles
1 August 2017 05:46

find tires online

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Much thanks for composing such a fascinating article on this point. This has truly made me think and I want to peruse more. find tires online

<
  • 0 Comments
  • 0 Articles
4 August 2017 04:14

top florida pr firms

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This post is really magnificent. I really like this post. It is one of the best posts that I ve read in a long time. Thanks a lot for this really good post. I really appreciate it! top florida pr firms

<
  • 0 Comments
  • 0 Articles
10 August 2017 02:20

free press release distribution

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Very well written post and very helpful to me. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. free press release distribution

<
  • 0 Comments
  • 0 Articles
11 August 2017 06:34

buy designer shoes online

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon… buy designer shoes online

<
  • 0 Comments
  • 0 Articles
14 August 2017 21:40

find tires online

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Thanks so much with this fantastic new web site. I’m very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world. find tires online

<
  • 0 Comments
  • 0 Articles
18 August 2017 21:48

lifestyle pr

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. lifestyle pr

<
  • 0 Comments
  • 0 Articles
25 August 2017 05:06

press release app

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
A debt of gratitude is in order for your data, it was truly exceptionally helpfull.. press release app

<
  • 0 Comments
  • 0 Articles
27 August 2017 05:44

goevo

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
The post is composed in exceptionally a decent way and it contains numerous helpful data for me. goevo

<
  • 0 Comments
  • 0 Articles
31 August 2017 05:21

david

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Great post. I found your website perfect for my needs. Very useful info specifically the last part. Thank you for sharing with us, and we sincerely hope you will continue to update or post other articles florida pr firms

<
  • 0 Comments
  • 0 Articles
1 September 2017 02:24

john

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. connect with journalists

<
  • 0 Comments
  • 0 Articles
3 September 2017 00:35

david

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Thanks for a wonderful share. Your article has importations your hard work and experience you have got in This field. Brilliant reading .I love it. water restoration urbana il

<
  • 0 Comments
  • 0 Articles
6 September 2017 04:40

john

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I appreciate your working style at the end just my request is please share with us some more great post. lifestyle public relations

<
  • 0 Comments
  • 0 Articles
14 September 2017 04:14

david

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. sending a pr release

<
  • 0 Comments
  • 0 Articles
19 September 2017 05:47

john

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Extremely pleasant article, I appreciated perusing your post, exceptionally decent share, I need to twit this to my adherents. Much appreciated! https://www.aaatreeserviceny.com/

<
  • 0 Comments
  • 0 Articles
30 September 2017 19:13

john

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Totally awesome posting! Loads of valuable data and motivation, both of which we all need!Relay welcome your work. Wedding Party Bus NJ

<
  • 0 Comments
  • 0 Articles
4 October 2017 01:37

david

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Your work is very good and I appreciate you for doing great job and hoping for some more valuable posts! mobile pr

<
  • 0 Comments
  • 0 Articles
11 October 2017 21:29

mellisa

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This is a decent post. This post gives really quality data. I'm certainly going to investigate it. Truly extremely helpful tips are given here. Much thanks to you to such an extent. Keep up the acts of kindness. pr agencies

<
  • 0 Comments
  • 0 Articles
9 November 2017 06:02

john

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as. website

<
  • 0 Comments
  • 0 Articles
15 November 2017 14:16

Anna Shetty

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post
photoshop alternative free, play cool math games run 3

<
  • 0 Comments
  • 0 Articles
16 November 2017 16:30

sarah

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Your post is so fascinating and enlightening a debt of gratitude is in order for sharing it. this post is useful for me. I will visit here once more. a debt of gratitude is in order for sharing it. wallets for men

Previous Next
Information
Comment on the news site is possible only within (days) days from the date of publication.