1.在網(wǎng)上粘了一個(gè)秒表的html代碼,可是希望通過(guò)執(zhí)行某個(gè)函數(shù)或者按鍵來(lái)控制秒表的開(kāi)始和暫停。
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<style type="text/css">
body{
background:white;
}
.container {
padding: 50px;
text-align: center;
}
.timer {
padding: 10px;
background: -webkit-linear-gradient(top, #222, #444);
background: -moz-linear-gradient(top, #222, #444);
background: -ms-linear-gradient(top, #222, #444);
background: -o-linear-gradient(top, #222, #444);
background: linear-gradient(top, #222, #444);
overflow: hidden;
display: inline-block;
border: 7px solid #efefef;
border-radius: 5px;
position: relative;
box-shadow: inset 0 -2px 10px 1px rgba(0, 0, 0, 0.75), 0 5px 20px -10px rgba(0, 0, 0, 1);
}
.cell {
/*只顯示一位數(shù)字. 高度 = 數(shù)字的行高,寬度 = 數(shù)字的寬度*/
width: 0.60em;
height: 40px;
font-size: 50px;
overflow: hidden;
position: relative;
float: left;
}
.numbers {
width: 0.6em;
line-height: 40px;
font-family: digital, arial, verdana;
text-align: center;
color: #fff;
position: absolute;
top: 0;
left: 0;
/*數(shù)字發(fā)光效果*/
text-shadow: 0 0 5px rgba(255, 255, 255, 1);
}
/*秒表控制器樣式*/
#timer_controls {
margin-top: -5px;
}
#timer_controls label {
cursor: pointer;
padding: 5px 10px;
background: #efefef;
font-family: arial, verdana, tahoma;
font-size: 11px;
border-radius: 0 0 3px 3px;
}
input[name="controls"] {display: none;}
/*Control code*/
/*秒表暫停運(yùn)轉(zhuǎn)*/
#stop:checked~.timer .numbers {
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
-ms-animation-play-state: paused;
animation-play-state: paused;
}
/*秒表開(kāi)始運(yùn)轉(zhuǎn)*/
#start:checked~.timer .numbers {
-webkit-animation-play-state: running;
-moz-animation-play-state: running;
-o-animation-play-state: running;
-ms-animation-play-state: running;
animation-play-state: running;
}
/*重置秒表*/
#reset:checked~.timer .numbers {
-webkit-animation: none;
-moz-animation: none;
-o-animation: none;
-ms-animation: none;
animation: none;
}
.moveten {
/*使用分步驟來(lái)移動(dòng)數(shù)字,10個(gè)數(shù)字即是10步*/
-webkit-animation: moveten 1s steps(10, end) infinite;
-moz-animation: moveten 1s steps(10, end) infinite;
-o-animation: moveten 1s steps(10, end) infinite;
-ms-animation: moveten 1s steps(10, end) infinite;
animation: moveten 1s steps(10, end) infinite;
/*默認(rèn)情況下動(dòng)畫停止不動(dòng)的*/
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
-ms-animation-play-state: paused;
animation-play-state: paused;
}
.movesix {
-webkit-animation: movesix 1s steps(6, end) infinite;
-moz-animation: movesix 1s steps(6, end) infinite;
-o-animation: movesix 1s steps(6, end) infinite;
-ms-animation: movesix 1s steps(6, end) infinite;
animation: movesix 1s steps(6, end) infinite;
}
/*同步時(shí)間的速率*/
/*每秒十個(gè)數(shù)字,因此也需要十步*/
.second {
-webkit-animation-duration: 10s;
-moz-animation-duration: 10s;
-o-animation-duration: 10s;
-ms-animation-duration: 10s;
animation-duration: 10s;
}
.tensecond {
/*60 times .second*/
-webkit-animation-duration: 60s;
-moz-animation-duration: 60s;
-o-animation-duration: 60s;
-ms-animation-duration: 60s;
animation-duration: 60s;
}
.milisecond {
/*1/10th of .second*/
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-o-animation-duration: 1s;
-ms-animation-duration: 1s;
animation-duration: 1s;
}
.tenmilisecond {
-webkit-animation-duration: 0.1s;
-moz-animation-duration: 0.1s;
-ms-animation-duration: 0.1s;
-o-animation-duration: 0.1s;
animation-duration: 0.1s;
}
.hundredmilisecond {
-webkit-animation-duration: 0.01s;
-moz-animation-duration: 0.01s;
-o-animation-duration: 0.01s;
-ms-animation-duration: 0.01s;
animation-duration: 0.01s;
}
.minute {
/*60 times .second*/
-webkit-animation-duration: 600s;
-moz-animation-duration: 600s;
-o-animation-duration: 600s;
-ms-animation-duration: 600s;
animation-duration: 600s;
}
.tenminute {
/*60 times .minute*/
-webkit-animation-duration: 3600s;
-moz-animation-duration: 3600s;
-ms-animation-duration: 3600s;
-o-animation-duration: 3600s;
animation-duration: 3600s;
}
.hour {
/*60 times .minute*/
-webkit-animation-duration: 36000s;
-moz-animation-duration: 36000s;
-ms-animation-duration: 36000s;
-o-animation-duration: 36000s;
animation-duration: 36000s;
}
.tenhour {
/*10 times .hour*/
-webkit-animation-duration: 360000s;
-moz-animation-duration: 360000s;
-o-animation-duration: 360000s;
-ms-animation-duration: 360000s;
animation-duration: 360000s;
}
@-webkit-keyframes moveten {
0% {top: 0;}
100% {top: -400px;}
/*height = 40. digits = 10. hence -400 to move it completely to the top*/
}
@-webkit-keyframes movesix {
0% {top: 0;}
100% {top: -240px;}
/*height = 40. digits = 6. hence -240 to move it completely to the top*/
}
@-moz-keyframes moveten {
0% {top: 0;}
100% {top: -400px;}
/*height = 40. digits = 10. hence -400 to move it completely to the top*/
}
@-moz-keyframes movesix {
0% {top: 0;}
100% {top: -240px;}
/*height = 40. digits = 6. hence -240 to move it completely to the top*/
}
@-o-keyframes moveten {
0% {top: 0;}
100% {top: -400px;}
/*height = 40. digits = 10. hence -400 to move it completely to the top*/
}
@-o-keyframes movesix {
0% {top: 0;}
100% {top: -240px;}
/*height = 40. digits = 6. hence -240 to move it completely to the top*/
}
@-ms-keyframes moveten {
0% {top: 0;}
100% {top: -400px;}
/*height = 40. digits = 10. hence -400 to move it completely to the top*/
}
@-ms-keyframes movesix {
0% {top: 0;}
100% {top: -240px;}
/*height = 40. digits = 6. hence -240 to move it completely to the top*/
}
@keyframes moveten {
0% {top: 0;}
100% {top: -400px;}
/*height = 40. digits = 10. hence -400 to move it completely to the top*/
}
@keyframes movesix {
0% {top: 0;}
100% {top: -240px;}
/*height = 40. digits = 6. hence -240 to move it completely to the top*/
}
/*Lets use a better font for the numbers*/
@font-face {
font-family: 'digital';
src: url('http://thecodeplayer.com/uploads/fonts/DS-DIGI.TTF');
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<div class="page">
<section class="demo">
<div class="container">
<!-- time to add the controls -->
<input id="start" name="controls" type="radio" />
<input id="stop" name="controls" type="radio" />
<input id="reset" name="controls" type="radio" />
<div class="timer">
<div class="cell">
<div class="numbers tenhour moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell">
<div class="numbers hour moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell divider"><div class="numbers">:</div></div>
<div class="cell">
<div class="numbers tenminute movesix">0 1 2 3 4 5 6</div>
</div>
<div class="cell">
<div class="numbers minute moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell divider"><div class="numbers">:</div></div>
<div class="cell">
<div class="numbers tensecond movesix">0 1 2 3 4 5 6</div>
</div>
<div class="cell">
<div class="numbers second moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell divider"><div class="numbers">:</div></div>
<div class="cell">
<div class="numbers milisecond moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell">
<div class="numbers tenmilisecond moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
<div class="cell">
<div class="numbers hundredmilisecond moveten">0 1 2 3 4 5 6 7 8 9</div>
</div>
</div>
<!-- Lables for the controls -->
<div id="timer_controls">
<label for="start">開(kāi)始</label>
<label for="stop">暫停</label>
<label for="reset">清零</label>
</div>
</div>
</div>
</body>
</html>
目前只能通過(guò) 點(diǎn)擊 label 來(lái)實(shí)現(xiàn)開(kāi)始和暫停,嘗試過(guò)JavaScript動(dòng)態(tài)的改變input的value屬性時(shí),自動(dòng)觸發(fā)oninput、onchange事件,可是沒(méi)有成功。有更簡(jiǎn)單的方法實(shí)現(xiàn)嗎?
https://segmentfault.com/q/10...
其實(shí)你看它控制的關(guān)鍵屬性是:
/*Control code*/
/*秒表暫停運(yùn)轉(zhuǎn)*/
#stop:checked~.timer .numbers {
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
-ms-animation-play-state: paused;
animation-play-state: paused;
}
/*秒表開(kāi)始運(yùn)轉(zhuǎn)*/
#start:checked~.timer .numbers {
-webkit-animation-play-state: running;
-moz-animation-play-state: running;
-o-animation-play-state: running;
-ms-animation-play-state: running;
animation-play-state: running;
}
/*重置秒表*/
#reset:checked~.timer .numbers {
-webkit-animation: none;
-moz-animation: none;
-o-animation: none;
-ms-animation: none;
animation: none;
}
就是用:checked
偽類觸發(fā)兄弟元素.timer
內(nèi)的.numbers
,變更animation的樣式和狀態(tài),那么你一樣也可以給.numbers
變更樣式啊。
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥(niǎo)中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過(guò)二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。