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

CSS3 and js simple digital clock code

CSS3 and js simple digital clock code

CSS3 and 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>
这是一款简单的自动获取本地时间的css3+js简单数字时钟代码,时分秒上下滚动动画切换网页时钟特效。 

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

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.

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.

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

Code for making a clock using Css3 and Js Code for making a clock using Css3 and Js

22 Jun 2018

This article mainly introduces the code for making clocks using Css3 and Js. It has certain reference value. Now I share it with you. Friends in need can refer to it.

Use css3 and js to implement a clock code process Use css3 and js to implement a clock code process

20 Sep 2018

What this article brings to you is about the process of using css3 and js to implement a clock code. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

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.

Make a simple clock using HTML5 and CSS3 Make a simple clock using HTML5 and CSS3

14 Sep 2017

Using HTML5 and CSS to achieve the pendulum effect is often encountered in projects. Today I will share the implementation code of a simple clock effect based on HTML5+CSS3 on the platform. Friends who need it can refer to it.

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.

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

Hot Article

Pokemon Pocket: How To Play With Friends
02 Nov 2024 Mobile Game Guide
All Black Ops 6 safehouse puzzle solutions
26 Oct 2024 Mobile Game Guide
Brotato: Best Hunter Build
13 Nov 2024 Mobile Game Guide
The Sims 4: Life & Death - Guardian Tree Guide
03 Nov 2024 Mobile Game Guide