CSS3 實(shí)現(xiàn)倒計(jì)時(shí)效果
發(fā)布時(shí)間:2020-11-25 16:53:19 作者:Yogev Ahuvia Love Settings Ch
我要評(píng)論
這篇文章主要介紹了CSS3 實(shí)現(xiàn)倒計(jì)時(shí)效果的示例代碼,幫助大家更好的理解和使用CSS3,感興趣的朋友可以了解下
實(shí)現(xiàn)效果

實(shí)現(xiàn)代碼
html
<div class='wrapper'>
<div class='time-part-wrapper'>
<div class='time-part minutes tens'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
<div class='time-part minutes ones'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>9</span>
<span class='digit'>8</span>
<span class='digit'>7</span>
<span class='digit'>6</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
</div>
<div class='time-part-wrapper'>
<div class='time-part seconds tens'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
<div class='time-part seconds ones'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>9</span>
<span class='digit'>8</span>
<span class='digit'>7</span>
<span class='digit'>6</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
</div>
<div class='time-part-wrapper'>
<div class='time-part hundredths tens'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>9</span>
<span class='digit'>8</span>
<span class='digit'>7</span>
<span class='digit'>6</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
<div class='time-part hundredths ones'>
<div class='digit-wrapper'>
<span class='digit'>0</span>
<span class='digit'>9</span>
<span class='digit'>8</span>
<span class='digit'>7</span>
<span class='digit'>6</span>
<span class='digit'>5</span>
<span class='digit'>4</span>
<span class='digit'>3</span>
<span class='digit'>2</span>
<span class='digit'>1</span>
<span class='digit'>0</span>
</div>
</div>
</div>
</div>
css
/* Play with speed and easing of the animation */
/* =========================================== */
.digit {
display: inline-block;
font-size: 200px;
color: rgba(0, 0, 0, 0.25);
height: 180px;
line-height: 1;
}
.time-part-wrapper {
display: inline-block;
margin-right: 50px;
position: relative;
}
.time-part-wrapper:not(:last-child):after {
content: ":";
display: block;
width: 30px;
height: 230px;
position: absolute;
top: 0px;
right: -30px;
color: rgba(0, 0, 0, 0.25);
font-size: 200px;
line-height: 0.9;
}
.time-part {
width: 140px;
text-align: center;
height: 180px;
overflow: hidden;
display: inline-block;
margin-left: -5px;
box-sizing: border-box;
}
.time-part .digit-wrapper {
animation-timing-function: cubic-bezier(1, 0, 1, 0);
}
.time-part.minutes.tens .digit-wrapper {
animation-name: minutes-tens;
animation-duration: 3600s;
animation-iteration-count: 1;
}
.time-part.minutes.ones .digit-wrapper {
animation-name: minutes-ones;
animation-duration: 600s;
animation-iteration-count: 6;
}
.time-part.seconds.tens .digit-wrapper {
animation-name: seconds-tens;
animation-duration: 60s;
animation-iteration-count: 60;
}
.time-part.seconds.ones .digit-wrapper {
animation-name: seconds-ones;
animation-duration: 10s;
animation-iteration-count: 360;
}
.time-part.hundredths.tens .digit-wrapper {
animation-name: hundredths-tens;
animation-duration: 1s;
animation-iteration-count: 3600;
}
.time-part.hundredths.ones .digit-wrapper {
animation-name: hundredths-ones;
animation-duration: 0.1s;
animation-iteration-count: 36000;
}
@keyframes minutes-tens {
0% {
transform: translateY(-180px);
}
16.66667% {
transform: translateY(-360px);
}
33.33333% {
transform: translateY(-540px);
}
50% {
transform: translateY(-720px);
}
66.66667% {
transform: translateY(-900px);
}
83.33333% {
transform: translateY(-1080px);
}
}
@keyframes minutes-ones {
0% {
transform: translateY(-180px);
}
10% {
transform: translateY(-360px);
}
20% {
transform: translateY(-540px);
}
30% {
transform: translateY(-720px);
}
40% {
transform: translateY(-900px);
}
50% {
transform: translateY(-1080px);
}
60% {
transform: translateY(-1260px);
}
70% {
transform: translateY(-1440px);
}
80% {
transform: translateY(-1620px);
}
90% {
transform: translateY(-1800px);
}
}
@keyframes seconds-tens {
0% {
transform: translateY(-180px);
}
16.66667% {
transform: translateY(-360px);
}
33.33333% {
transform: translateY(-540px);
}
50% {
transform: translateY(-720px);
}
66.66667% {
transform: translateY(-900px);
}
83.33333% {
transform: translateY(-1080px);
}
}
@keyframes seconds-ones {
0% {
transform: translateY(-180px);
}
10% {
transform: translateY(-360px);
}
20% {
transform: translateY(-540px);
}
30% {
transform: translateY(-720px);
}
40% {
transform: translateY(-900px);
}
50% {
transform: translateY(-1080px);
}
60% {
transform: translateY(-1260px);
}
70% {
transform: translateY(-1440px);
}
80% {
transform: translateY(-1620px);
}
90% {
transform: translateY(-1800px);
}
}
@keyframes hundredths-tens {
0% {
transform: translateY(-180px);
}
10% {
transform: translateY(-360px);
}
20% {
transform: translateY(-540px);
}
30% {
transform: translateY(-720px);
}
40% {
transform: translateY(-900px);
}
50% {
transform: translateY(-1080px);
}
60% {
transform: translateY(-1260px);
}
70% {
transform: translateY(-1440px);
}
80% {
transform: translateY(-1620px);
}
90% {
transform: translateY(-1800px);
}
}
@keyframes hundredths-ones {
0% {
transform: translateY(-180px);
}
10% {
transform: translateY(-360px);
}
20% {
transform: translateY(-540px);
}
30% {
transform: translateY(-720px);
}
40% {
transform: translateY(-900px);
}
50% {
transform: translateY(-1080px);
}
60% {
transform: translateY(-1260px);
}
70% {
transform: translateY(-1440px);
}
80% {
transform: translateY(-1620px);
}
90% {
transform: translateY(-1800px);
}
}
body {
background: #F1614B;
margin: 0;
font-family: "Aldrich";
}
.wrapper {
margin: 100px auto;
width: 1000px;
position: relative;
}
.wrapper:before, .wrapper:after {
content: "";
display: block;
position: absolute;
width: 100%;
left: 0;
height: 20px;
z-index: 10;
}
.wrapper:before {
top: 0px;
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2YxNjE0YiIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2YxNjE0YiIgc3RvcC1vcGFjaXR5PSIwLjAiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2dyYWQpIiAvPjwvc3ZnPiA=');
background-size: 100%;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f1614b), color-stop(100%, rgba(241, 97, 75, 0)));
background-image: -moz-linear-gradient(top, #f1614b 0%, rgba(241, 97, 75, 0) 100%);
background-image: -webkit-linear-gradient(top, #f1614b 0%, rgba(241, 97, 75, 0) 100%);
background-image: linear-gradient(to bottom, #f1614b 0%, rgba(241, 97, 75, 0) 100%);
}
.wrapper:after {
bottom: 0px;
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2YxNjE0YiIgc3RvcC1vcGFjaXR5PSIwLjAiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmMTYxNGIiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2dyYWQpIiAvPjwvc3ZnPiA=');
background-size: 100%;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, rgba(241, 97, 75, 0)), color-stop(100%, #f1614b));
background-image: -moz-linear-gradient(top, rgba(241, 97, 75, 0) 0%, #f1614b 100%);
background-image: -webkit-linear-gradient(top, rgba(241, 97, 75, 0) 0%, #f1614b 100%);
background-image: linear-gradient(to bottom, rgba(241, 97, 75, 0) 0%, #f1614b 100%);
}
以上就是CSS3 實(shí)現(xiàn)倒計(jì)時(shí)效果的詳細(xì)內(nèi)容,更多關(guān)于CSS3 倒計(jì)時(shí)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章

CSS3 最強(qiáng)二維布局系統(tǒng)之Grid 網(wǎng)格布局
CS3的Grid網(wǎng)格布局是目前最強(qiáng)的二維布局系統(tǒng),可以同時(shí)對(duì)列和行進(jìn)行處理,將網(wǎng)頁(yè)劃分成一個(gè)個(gè)網(wǎng)格,可以任意組合不同的網(wǎng)格,做出各種各樣的布局,本文介紹CSS3 最強(qiáng)二維布局系2025-02-27- 本文介紹了如何使用CSS3的transform屬性和動(dòng)畫技巧實(shí)現(xiàn)波浪式圖片墻,通過設(shè)置圖片的垂直偏移量,并使用動(dòng)畫使其周期性地改變位置,可以創(chuàng)建出動(dòng)態(tài)且具有波浪效果的圖片墻,同2025-02-27

CSS3模擬實(shí)現(xiàn)一個(gè)雷達(dá)探測(cè)掃描動(dòng)畫特效(最新推薦)
文章介紹了如何使用CSS3實(shí)現(xiàn)一個(gè)雷達(dá)探測(cè)掃描的效果,包括夜色背景、蜘蛛網(wǎng)盤、掃描體的轉(zhuǎn)動(dòng)效果、尾巴陰影以及被掃描到的光點(diǎn),通過HTML和CSS的配合,實(shí)現(xiàn)了豐富的動(dòng)畫效果,2025-02-21- CSS3的Flexbox是一種強(qiáng)大的布局模式,通過設(shè)置display:flex可以輕松實(shí)現(xiàn)對(duì)齊、排列和分布網(wǎng)頁(yè)元素,它解決了傳統(tǒng)布局方法中的對(duì)齊、間距分配和自適應(yīng)布局等問題,接下來通過本2025-02-19

css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果
本文給大家介紹css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果,文章開頭給大家介紹了webkit-transform、animation、@keyframes這三個(gè)屬性,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一2025-02-19CSS3動(dòng)態(tài)效果之過渡屬性(最新推薦)
CSS3過渡屬性用于實(shí)現(xiàn)元素從一種樣式平滑過渡到另一種樣式,通過設(shè)置transition-property過渡屬性、transition-duration過渡時(shí)長(zhǎng)transition-timing-function過渡函數(shù)和trans2025-02-19CSS3實(shí)現(xiàn)動(dòng)態(tài)旋轉(zhuǎn)加載樣式的示例代碼
本文介紹了如何使用CSS3創(chuàng)建一個(gè)簡(jiǎn)單的動(dòng)態(tài)旋轉(zhuǎn)加載樣式,通過定義一個(gè)帶有類名“l(fā)oader”的HTML元素,并使用CSS樣式和@keyframes規(guī)則來實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫,你可以根據(jù)需要調(diào)整樣式2025-02-19使用CSS3實(shí)現(xiàn)平滑的過渡動(dòng)畫效果(實(shí)例代碼)
這篇文章主要介紹了如何使用CSS3的transition屬性實(shí)現(xiàn)平滑的過渡動(dòng)畫,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2025-02-13
CSS3中使用flex和grid實(shí)現(xiàn)等高元素布局的示例代碼
本文介紹了使用CSS3中的Flexbox和Grid布局實(shí)現(xiàn)等高元素布局的方法,通過簡(jiǎn)單的兩列實(shí)現(xiàn)、每行放置3列以及全部代碼的展示,展示了這兩種布局方式的實(shí)現(xiàn)細(xì)節(jié)和效果,感興趣的朋2025-02-11使用CSS3和SVG創(chuàng)建圓形進(jìn)度條動(dòng)畫效果
CSS3和SVG的結(jié)合使用為網(wǎng)頁(yè)設(shè)計(jì)帶來了創(chuàng)新的動(dòng)態(tài)視覺效果,本文通過一個(gè)圓形進(jìn)度條的動(dòng)畫特效示例,展示了如何利用CSS3的動(dòng)畫功能和SVG的矢量圖形能力來創(chuàng)建豐富的用戶交互體2024-10-24





