欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何使用jQuery+localStorage實(shí)現(xiàn)計(jì)時(shí)器

這篇文章將為大家詳細(xì)講解有關(guān)如何使用jQuery+localStorage實(shí)現(xiàn)計(jì)時(shí)器,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供臨江企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、成都網(wǎng)站建設(shè)、HTML5、小程序制作等業(yè)務(wù)。10年已為臨江眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

原型

如何使用jQuery+localStorage實(shí)現(xiàn)計(jì)時(shí)器

需求

       1.關(guān)閉瀏覽器時(shí)時(shí)間繼續(xù)運(yùn)行

      2.刷新時(shí)保持當(dāng)前狀態(tài)

      3.結(jié)束時(shí)間保存在客戶端

示例代碼

 <div class="wrapper">
  <div class="app">
  <div class="container stopwatch">   
   <div class="clock inactive z-depth-1">
   <span>0:00:00</span>
   <!-- <div class="overlay waves-effect"></div>-->
   </div>   
   <form>
   <a id="stopwatch-btn-start" class="waves-effect waves-teal btn-flat">開始</a>
  
   </form>
   
  </div>
  </div>
 </div>
<script> 
 // Stopwatch
var stopwatchInterval = 0; // The interval for our loop.循環(huán)的間隔。 
var stopwatchClock = $(".container.stopwatch").find(".clock"),
 stopwatchDigits = stopwatchClock.find('span');
// 檢查前一個(gè)會(huì)話是否在秒表運(yùn)行時(shí)結(jié)束。 
// 如果是的話,按時(shí)間重新開始。 
//即 關(guān)閉瀏覽器,點(diǎn)擊開始,在后臺(tái)保持計(jì)時(shí)的狀態(tài)
if(Number(localStorage.stopwatchBeginingTimestamp) && Number(localStorage.stopwatchRunningTime)){
 var runningTime = Number(localStorage.stopwatchRunningTime) + new Date().getTime() - Number(localStorage.stopwatchBeginingTimestamp);
 localStorage.stopwatchRunningTime = runningTime;
 startStopwatch();
}
//如果前一個(gè)會(huì)話有運(yùn)行時(shí)間,就把它寫在時(shí)鐘上。
// 如果沒有初始化為0。 
//即結(jié)束時(shí)不可刷新
if(localStorage.stopwatchRunningTime){
 
 stopwatchDigits.text(returnFormattedToMilliseconds(Number(localStorage.stopwatchRunningTime)));
 
}
else{
 localStorage.stopwatchRunningTime = 0;
}
 /* 實(shí)現(xiàn)開始結(jié)束 */
 $("#stopwatch-btn-start").toggle(function() {
  $(this).text ('開始').css("background", "#3bb4f2");
  if(stopwatchClock.hasClass('inactive')){
  startStopwatch()
 }  
 }, function() {  
  $(this).text ('結(jié)束').css("background", "red");
  pauseStopwatch();
 }) 
// Pressing the clock will pause/unpause the stopwatch.
//按下暫停/恢復(fù)的時(shí)鐘秒表
/*stopwatchClock.on('click',function(){
 if(stopwatchClock.hasClass('inactive')){
 startStopwatch()
 }
 else{
 pauseStopwatch();
 }
});*/
/*開始計(jì)時(shí)*/
function startStopwatch(){
 // 防止多個(gè)間隔同時(shí)進(jìn)行。 
 clearInterval(stopwatchInterval);
 var startTimestamp = new Date().getTime(),
 runningTime = 0;
 localStorage.stopwatchBeginingTimestamp = startTimestamp;
 // 應(yīng)用程序還記得上一次會(huì)話運(yùn)行了多長時(shí)間。 
 if(Number(localStorage.stopwatchRunningTime)){
 runningTime = Number(localStorage.stopwatchRunningTime);
 }
 else{
 localStorage.stopwatchRunningTime = 1;
 }
 // 每隔100ms重新計(jì)算運(yùn)行時(shí)間,計(jì)算公式是 
 // 當(dāng)你上次啟動(dòng)時(shí)鐘+上次運(yùn)行時(shí)間 
 stopwatchInterval = setInterval(function () {
 var stopwatchTime = (new Date().getTime() - startTimestamp + runningTime);
 stopwatchDigits.text(returnFormattedToMilliseconds(stopwatchTime));
 }, 100);
 stopwatchClock.removeClass('inactive');
}
/*停止計(jì)時(shí)*/
function pauseStopwatch(){
 // 停止計(jì)時(shí) 
 clearInterval(stopwatchInterval);
 if(Number(localStorage.stopwatchBeginingTimestamp)){
 // 計(jì)算運(yùn)行時(shí)間。 
 // 新的運(yùn)行時(shí)間=上次運(yùn)行時(shí)間+現(xiàn)在-最后一次啟動(dòng) 
 var runningTime = Number(localStorage.stopwatchRunningTime) + new Date().getTime() - Number(localStorage.stopwatchBeginingTimestamp);
 localStorage.stopwatchBeginingTimestamp = 0;
 localStorage.stopwatchRunningTime = runningTime;
 stopwatchClock.addClass('inactive');
 }
}
// 重置.
/*function resetStopwatch(){
 clearInterval(stopwatchInterval);
 stopwatchDigits.text(returnFormattedToMilliseconds(0));
 localStorage.stopwatchBeginingTimestamp = 0;
 localStorage.stopwatchRunningTime = 0;

 stopwatchClock.addClass('inactive');
}
*/
function returnFormattedToMilliseconds(time){
 var 
 seconds = Math.floor((time/1000) % 60),
 minutes = Math.floor((time/(1000*60)) % 60),
 hours = Math.floor((time/(1000*60*60)) % 24);
 seconds = seconds < 10 ? '0' + seconds : seconds;
 minutes = minutes < 10 ? '0' + minutes : minutes;
 return hours + ":" + minutes + ":" + seconds;
}
</script>

關(guān)于“如何使用jQuery+localStorage實(shí)現(xiàn)計(jì)時(shí)器”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

本文題目:如何使用jQuery+localStorage實(shí)現(xiàn)計(jì)時(shí)器
網(wǎng)站鏈接:http://aaarwkj.com/article0/ihpeoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)建站公司、響應(yīng)式網(wǎng)站Google面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
国产精品免费网站在线观看| 2020中文字字幕在线不卡| 草莓午夜视频在线观看| 男人的天堂av东京热一区| 漂亮人妻被中出中文字幕| 91久久福利国产成人精品| 亚洲av优选在线观看精品| 男人的天堂在线观看黄片| 国产一区二区三区免费有码视频| 东京男人的天堂国产av| 国产日韩综合精品一区| 国产三级三级三级三级三级| 五月天色婷婷亚洲综合一区| 国产日韩精品综合一区| 中文字幕熟妇人妻av在线| 欧美日韩一级一区二区| 夫妻性生活免费的视频| 亚洲精品隔壁傲慢人妻| 精品亚洲在线一区二区| 男人天堂手机视频在线| 国产精品久久123区| 人妻少妇被猛烈进入久久精品| 中文字幕av在线日韩| 亚洲精品永久在线观看| 91精品国产自产在线蜜臀| 免费毛片一区二区三区| 亚洲欧洲日韩综合另类| 国产偷国产偷亚洲综合av| 国产免费播放一区二区三区| 国产女主播精品视频一区| 在线观看免费在线观看免费| 校园春色亚洲欧美日韩| 欧美日韩一区二区三区色拉拉| 亚洲欧洲精品专线九九| 亚洲美女高清一区二区三区| 内射极品美女在线观看| 国产精品一级片免费看| 亚洲激情一区在线观看| 亚洲中文字幕一区乱码| 亚洲av日韩av一区| 国产精品一区二区综合亚洲|