自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

CSS3動(dòng)態(tài)進(jìn)度條及jQ百分比數(shù)字顯示

開發(fā) 前端
今天就為大家分享一個(gè)利用css3制作動(dòng)態(tài)進(jìn)度條以及附加jQuery百分比數(shù)字顯示。其效果對(duì)比flash來說卻毫不遜色,有一個(gè)精致的動(dòng)畫進(jìn)度條,上面還有當(dāng)前進(jìn)度的百分比數(shù)字顯示,而且還會(huì)跟著進(jìn)度條而移動(dòng)。相信追求新穎的朋友來說一定會(huì)非常的喜歡。

在網(wǎng)頁設(shè)計(jì)中,想必一個(gè)精彩的進(jìn)度條將會(huì)為你的網(wǎng)站增添不少的精彩,一個(gè)好的網(wǎng)頁設(shè)計(jì)往往體現(xiàn)在一些小的細(xì)節(jié)上面,細(xì)節(jié)決定了成功與否。在此之前也為大家分享了一些關(guān)于進(jìn)度條的設(shè)計(jì) ― 讓人不得不愛的22個(gè)UI進(jìn)度條設(shè)計(jì)。有了設(shè)計(jì)理念和作品,那我們?cè)趺从米罹实姆椒ㄟ\(yùn)用到我們的網(wǎng)頁制作當(dāng)中呢﹖

今天就為大家分享一個(gè)利用css3制作動(dòng)態(tài)進(jìn)度條以及附加jQuery百分比數(shù)字顯示。其效果對(duì)比flash來說卻毫不遜色,有一個(gè)精致的動(dòng)畫進(jìn)度條,上面還有當(dāng)前進(jìn)度的百分比數(shù)字顯示,而且還會(huì)跟著進(jìn)度條而移動(dòng)。相信追求新穎的朋友來說一定會(huì)非常的喜歡。

查看預(yù)覽

HTML代碼

HTML的代碼非常簡(jiǎn)單,只要為進(jìn)度條提供一個(gè)容器就可以了?;镜腍TML代碼如下:

  1. <div class="wrapper"> 
  2.   <div class="load-bar"> 
  3.     <div class="load-bar-inner" data-loading="0"> <span id="counter"></span> </div> 
  4.   </div> 
  5.   <h1>Loading</h1> 
  6.   <p>Please wait...(By:<a href="http://www.jiawin.com">www.jiawin.com</a>)</p> 
  7. </div> 

CSS樣式表

接下來是為我們的進(jìn)度條定義樣式,這里主要運(yùn)用了CSS3的linear-gradient的漸變屬性、border-radius的圓角屬性、 box-shadow的陰影屬性等等,來制作出進(jìn)度條的初步模型。完成進(jìn)度條的模型后我們利用animation屬性,讓進(jìn)度條開始動(dòng)起來,就其中的進(jìn)度條動(dòng)畫設(shè)置代碼如下:

  1. .load-bar-inner {  
  2.     height99%;  
  3.     width0%;  
  4.     border-radius: inherit;  
  5.     positionrelative;  
  6.     background#c2d7ac;  
  7.     background: linear-gradient(#e0f6c8#98ad84);  
  8.     box-shadow: inset 0 1px 0 rgba(2552552551),  0 1px 5px rgba(0000.3),  0 4px 5px rgba(0000.3);  
  9.     animation: loader 10s linear infinite;  

如果接觸了CSS3的朋友,相信大多數(shù)人對(duì)這個(gè)屬性都比較熟悉了,在這里大概的說明一下animation設(shè)置的參數(shù):

設(shè)置對(duì)象所應(yīng)用的動(dòng)畫名稱:loader

設(shè)置對(duì)象動(dòng)畫的持續(xù)時(shí)間:10s

設(shè)置對(duì)象動(dòng)畫的過渡類型:linear (線性過渡,等同于貝塞爾曲線)

設(shè)置對(duì)象動(dòng)畫的循環(huán)次數(shù):infinite (無限循環(huán))

@keyframes loader這個(gè)標(biāo)簽屬性是用來被animation使用的,定義動(dòng)畫時(shí),簡(jiǎn)單的動(dòng)畫可以直接使用關(guān)鍵字from和to,即從一種狀態(tài)過渡到另一種狀態(tài):

  1. @keyframes loader {  
  2.  from {  
  3. width: 0%;  
  4. }  
  5. to {  
  6.     width: 100%;  
  7. }  

下面是完整的CSS代碼,大家可以多研究下,也可以自己修改其中的代碼,看看是否制作出更加有趣的東西來:

  1. * {  
  2.     box-sizing: border-box;  
  3. }  
  4. html {  
  5.     height: 100%;  
  6. }  
  7. body {  
  8.     background: #efeeea;  
  9.     background: linear-gradient(#f9f9f9, #cecbc4);  
  10.     background: -moz-linear-gradient(#f9f9f9, #cecbc4);  
  11.     background: -webkit-linear-gradient(#f9f9f9, #cecbc4);  
  12.     background: -o-linear-gradient(#f9f9f9, #cecbc4);  
  13.     color: #757575;  
  14.     font-family: "HelveticaNeue-Light""Helvetica Neue Light""Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;  
  15.     text-align: center;  
  16. }  
  17. h1, p {  
  18.     padding:0; margin:0;  
  19. }  
  20. .wrapper {  
  21.     width: 350px;  
  22.     margin: 200px auto;  
  23. }  
  24. .wrapper p a {color:#757575; text-decoration:none;}  
  25. .wrapper .load-bar {  
  26.     width: 100%;  
  27.     height: 25px;  
  28.     border-radius: 30px;  
  29.     background: #dcdbd7;  
  30.     position: relative;  
  31.     box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8),  inset 0 2px 3px rgba(0, 0, 0, 0.2);  
  32. }  
  33. .wrapper .load-bar:hover .load-bar-inner, .wrapper .load-bar:hover #counter {  
  34.     animation-play-state: paused;  
  35.     -moz-animation-play-state: paused;  
  36.     -o-animation-play-state: paused;  
  37.     -webkit-animation-play-state: paused;  
  38. }  
  39. .wrapper .load-bar-inner {  
  40.     height: 99%;  
  41.     width: 0%;  
  42.     border-radius: inherit;  
  43.     position: relative;  
  44.     background: #c2d7ac;  
  45.     background: linear-gradient(#e0f6c8, #98ad84);  
  46.     background: -moz-linear-gradient(#e0f6c8, #98ad84);  
  47.     background: -webkit-linear-gradient(#e0f6c8, #98ad84);  
  48.     background: -o-linear-gradient(#e0f6c8, #98ad84);  
  49.     box-shadow: inset 0 1px 0 rgba(255, 255, 255, 1),  0 1px 5px rgba(0, 0, 0, 0.3),  0 4px 5px rgba(0, 0, 0, 0.3);  
  50.     animation: loader 10s linear infinite;  
  51.     -moz-animation: loader 10s linear infinite;  
  52.     -webkit-animation: loader 10s linear infinite;  
  53.     -o-animation: loader 10s linear infinite;  
  54. }  
  55. .wrapper #counter {  
  56.     position: absolute;  
  57.     background: #eeeff3;  
  58.     background: linear-gradient(#eeeff3, #cbcbd3);  
  59.     background: -moz-linear-gradient(#eeeff3, #cbcbd3);  
  60.     background: -webkit-linear-gradient(#eeeff3, #cbcbd3);  
  61.     background: -o-linear-gradient(#eeeff3, #cbcbd3);  
  62.     padding: 5px 10px;  
  63.     border-radius: 0.4em;  
  64.     box-shadow: inset 0 1px 0 rgba(255, 255, 255, 1),  0 2px 4px 1px rgba(0, 0, 0, 0.2),  0 1px 3px 1px rgba(0, 0, 0, 0.1);  
  65.     left: -25px;  
  66.     top: -50px;  
  67.     font-size: 12px;  
  68.     font-weight: bold;  
  69.     width: 44px;  
  70.     animation: counter 10s linear infinite;  
  71.     -moz-animation: counter 10s linear infinite;  
  72.     -webkit-animation: counter 10s linear infinite;  
  73.     -o-animation: counter 10s linear infinite;  
  74. }  
  75. .wrapper #counter:after {  
  76.     content: "";  
  77.     position: absolute;  
  78.     width: 8px;  
  79.     height: 8px;  
  80.     background: #cbcbd3;  
  81.     transform: rotate(45deg);  
  82.     -moz-transform: rotate(45deg);  
  83.     -webkit-transform: rotate(45deg);  
  84.     -o-transform: rotate(45deg);  
  85.     left: 50%;  
  86.     margin-left: -4px;  
  87.     bottom: -4px;  
  88.     box-shadow:  3px 3px 4px rgba(0, 0, 0, 0.2),  1px 1px 1px 1px rgba(0, 0, 0, 0.1);  
  89.     border-radius: 0 0 3px 0;  
  90. }  
  91. .wrapper h1 {  
  92.     font-size: 28px;  
  93.     padding: 20px 0 8px 0;  
  94. }  
  95. .wrapper p {  
  96.     font-size: 13px;  
  97. }  
  98.  @keyframes loader {  
  99.  from {  
  100. width: 0%;  
  101. }  
  102. to {  
  103.     width: 100%;  
  104. }  
  105. }  
  106.  @-moz-keyframes loader {  
  107.  from {  
  108. width: 0%;  
  109. }  
  110. to {  
  111.     width: 100%;  
  112. }  
  113. }  
  114.  @-webkit-keyframes loader {  
  115.  from {  
  116. width: 0%;  
  117. }  
  118. to {  
  119.     width: 100%;  
  120. }  
  121. }  
  122.  @-o-keyframes loader {  
  123.  from {  
  124. width: 0%;  
  125. }  
  126. to {  
  127.     width: 100%;  
  128. }  
  129. }  
  130.  
  131.  @keyframes counter {  
  132.  from {  
  133. left: -25px;  
  134. }  
  135. to {  
  136.     left: 323px;  
  137. }  
  138. }  
  139.  @-moz-keyframes counter {  
  140.  from {  
  141. left: -25px;  
  142. }  
  143. to {  
  144.     left: 323px;  
  145. }  
  146. }  
  147.  @-webkit-keyframes counter {  
  148.  from {  
  149. left: -25px;  
  150. }  
  151. to {  
  152.     left: 323px;  
  153. }  
  154. }  
  155.  @-o-keyframes counter {  
  156.  from {  
  157. left: -25px;  
  158. }  
  159. to {  
  160.     left: 323px;  
  161. }  

在這里其實(shí)有很多個(gè)CSS3的知識(shí)點(diǎn),例如進(jìn)度條上面的進(jìn)度提示的小圖標(biāo)的下方有個(gè)小三角形,這個(gè)小三角主要是通過制作一個(gè)小的正方形,然后利用 position來定位,調(diào)整好位置后,再通過transform來轉(zhuǎn)換角度,使之最終成為一個(gè)三角形。大家可以多多看看里面的一些小細(xì)節(jié),對(duì)于學(xué)習(xí) CSS3來說是很有幫助的。

Javascript

完成了進(jìn)度條的模型,而且進(jìn)度條也通過CSS3的定義開始動(dòng)起來了,那我們就接下來用jQuery來完善我們的進(jìn)度條,讓他成為一個(gè)不管外表還是內(nèi)心都很強(qiáng)大的進(jìn)度條。嘿嘿…在這里主要做的是讓進(jìn)度條上面的數(shù)字隨著進(jìn)度而發(fā)生變化,從而客觀的知道當(dāng)前進(jìn)度條的進(jìn)度百分比,看下面的代碼:

  1. $(function(){  
  2.   var interval = setInterval(increment,100);  
  3.   var current = 0;  
  4.   function increment(){  
  5.     current++;  
  6.     $('#counter').html(current+'%');   
  7.     if(current == 100) { current = 0; }  
  8.   }  
  9.   $('.load-bar').mouseover(function(){  
  10.         clearInterval(interval);  
  11.   }).mouseout(function(){  
  12.       interval = setInterval(increment,100);  
  13.     });  
  14. }); 

這一步需要注意的是別忘了加入jQuery庫(kù),不然就看不到效果了。

原文鏈接:http://www.jiawin.com/css3-digital-progress-bar/

責(zé)任編輯:張偉 來源: Javin
相關(guān)推薦

2015-07-31 11:19:43

數(shù)字進(jìn)度條源碼

2013-03-12 10:35:06

CSS 3

2021-09-27 10:43:18

鴻蒙HarmonyOS應(yīng)用

2024-08-06 14:29:37

2011-03-31 16:16:43

Cacti監(jiān)控

2011-04-06 10:57:11

Cacti監(jiān)控

2024-05-11 08:11:19

CSS百分比開發(fā)

2024-12-02 09:37:51

2009-08-18 09:49:00

C# listview

2023-11-30 11:38:29

CSS網(wǎng)頁進(jìn)度條

2011-02-22 14:53:41

titlebar標(biāo)題欄Android

2012-05-07 10:13:39

CSS3

2021-09-26 08:22:51

CSS 技巧百分比

2009-08-17 13:56:29

C#進(jìn)度條的使用

2011-07-05 15:16:00

QT 進(jìn)度條

2009-08-17 15:05:41

C#進(jìn)度條

2021-11-02 07:44:36

CSS 技巧進(jìn)度條

2024-04-01 08:18:52

CSSHTMLWeb

2023-07-18 15:49:22

HTMLCSS

2021-03-01 14:00:11

鴻蒙HarmonyOS應(yīng)用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)