Home JS special effects CSS3 special effects CSS3+js simple digital clock code

CSS3+js simple digital clock code

CSS3+js simple digital clock code

CSS3+js simple digital clock code

js code

<script>
'use strict';

var size = 86;
var columns = Array.from(document.getElementsByClassName('column'));
var d = undefined,
    c = undefined;
var classList = ['visible', 'close', 'far', 'far', 'distant', 'distant'];
var use24HourClock = true;

function padClock(p, n) {
	return p + ('0' + n).slice(-2);
}

function getClock() {
	d = new Date();
	return [use24HourClock ? d.getHours() : d.getHours() % 12 || 12, d.getMinutes(), d.getSeconds()].reduce(padClock, '');
}

function getClass(n, i2) {
	return classList.find(function (class_, classIndex) {
		return i2 - classIndex === n || i2 + classIndex === n;
	}) || '';
}

var loop = setInterval(function () {
	c = getClock();

	columns.forEach(function (ele, i) {
		var n = +c[i];
		var offset = -n * size;
		ele.style.transform = 'translateY(calc(50vh + ' + offset + 'px - ' + size / 2 + 'px))';
		Array.from(ele.children).forEach(function (ele2, i2) {
			ele2.className = 'num ' + getClass(n, i2);
		});
	});
}, 200 + Math.E * 10);
</script>

This is a simple css3 js digital clock code that automatically obtains the local time, and scrolls up and down in hours, minutes and seconds to switch the web page clock effect.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

css3+js draws dynamic clock (with code) css3+js draws dynamic clock (with code)

20 Sep 2018

This chapter introduces how to use css3 and js to achieve dynamic clock effects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Making a digital clock based on Jquery and CSS3 with source code download (CSS3)_jquery Making a digital clock based on Jquery and CSS3 with source code download (CSS3)_jquery

16 May 2016

Digital clocks are used in web countdown, web alarm clock effects and web apps based on HTML5. This article introduces to you how to make a digital clock based on jquery and css3 with source code download. Interested friends can take a look.

How to skillfully use CSS3 special effects to improve the user experience of web pages How to skillfully use CSS3 special effects to improve the user experience of web pages

09 Sep 2023

How to skillfully use CSS3 special effects to improve the user experience of web pages. With the development of the Internet, web design and user experience have become important links in website development. The application of CSS3 special effects can add dynamics and visual effects to web pages and improve user experience. This article will introduce several common CSS3 special effects and their code examples to help developers become more proficient in using CSS3 special effects and improve the user experience of web pages. Transition effect (Transition) Transition effect is one of the most basic special effects in CSS3. By changing a certain attribute

Implementation of css3 visual effects Implementation of css3 visual effects

22 Mar 2018

This time I will bring you the implementation of CSS3 visual special effects. What are the precautions for realizing CSS3 visual special effects? The following is a practical case, let’s take a look.

Sharing of 7 eye-catching jQuery/CSS3 special effects examples_jquery Sharing of 7 eye-catching jQuery/CSS3 special effects examples_jquery

16 May 2016

jQuery and CSS3 are definitely used a lot for web front-end development. Next, I will share some special effects made by jQuery and CSS3. I hope it will be helpful to friends who like to learn special effects.

How to use css3 to achieve 3D stereoscopic effects How to use css3 to achieve 3D stereoscopic effects

14 Mar 2018

This time I will show you how to use css3 to achieve 3D stereoscopic special effects. What are the precautions for using css3 to achieve 3D stereoscopic special effects? The following is a practical case, let’s take a look.

CSS3 3D special effects video data sharing CSS3 3D special effects video data sharing

31 Aug 2017

"CSS3 3D Special Effects Video Tutorial" uses the transition attribute, perspective attribute, and transform attribute in CSS3 to create real and usable three-dimensional effects.

How to use JS to implement a simple digital clock How to use JS to implement a simple digital clock

11 Jul 2018

This article mainly introduces how to use JS to implement a simple digital clock. It has certain reference value. Now I share it with you. Friends in need can refer to it.

css3 effect rotation css3 effect rotation

27 May 2023

Rotation of CSS3 special effects In web design, dynamic special effects can increase the interactivity and artistry of web pages, making users browse web pages more happily. Among them, the rotation effect is a relatively common special effect. In CSS3, rotation effects can be achieved through the transform attribute. 1. Use transform to achieve rotation. The transform attribute in CSS3 is used to achieve deformation effects of elements, such as rotation, movement, scaling, etc. When realizing the element rotation effect, you can use the rotate rotation function. The specific syntax is as follows: tra

See all articles See all articles

Hot Tools

CSS text is combined into a heart-shaped animation special effect

CSS text is combined into a heart-shaped animation special effect

CSS text is combined into a heart-shaped animation special effect

CSS3 SVG expression flower animation special effects

CSS3 SVG expression flower animation special effects

SS3 SVG confession flower animation special effect is a Valentine's Day animation special effect.

CSS shopping mall websites commonly use left category drop-down navigation menu code

CSS shopping mall websites commonly use left category drop-down navigation menu code

CSS shopping mall websites commonly use left category drop-down navigation menu code

jQuery+CSS3 Valentine's Day love special effects

jQuery+CSS3 Valentine's Day love special effects

jQuery+CSS3 Valentine's Day Love Special Effect is a Valentine's Day hanging swinging heart animation special effect.

css3 spoon scooping up glutinous rice balls animation special effects

css3 spoon scooping up glutinous rice balls animation special effects

A bowl of cute glutinous rice balls expression, a spoon scooping up a glutinous rice balls animation special effects