帖子
帖子
用户
博客
课程
显示全部楼层
216
帖子
5
勋章
5909
Y币

myTimer模块demo示例

[复制链接]
发表于 2019-7-5 16:33:51
myTimer模块,实现了iOS、安卓系统计时器功能,可以实现延时、循环。(注意:由于iOS后台进程的限制,本模块向iOS申请后台额外后台任务执行时间[后台执行时间在app进入后台瞬间能申请到,并在接口回调中返回],如果定时器在申请时间内完成,模块正常调用,当超过申请时间则会被系统自动关闭回收。)

点击进入模块详情

  1. <!DOCTYPE html>
  2. <html>
  3.         <head>
  4.                 <title>Module Develop</title>
  5.                 <meta charset="utf-8">
  6.                 <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  7.                 <style type="text/css">
  8.                         html, body {
  9.                                 height: 100%
  10.                         }
  11.                         body {
  12.                                 background-color: #fff;
  13.                                 margin: 0;
  14.                         }
  15.                         #wrap {
  16.                                 height: 100%;
  17.                                 position: relative;
  18.                         }
  19.                         #header {
  20.                                 padding-top: 20px;
  21.                                 background-color: #5082c2;
  22.                                 height: 44px;
  23.                                 position: relative;
  24.                         }
  25.                         #header h1 {
  26.                                 font-size: 20px;
  27.                                 height: 44px;
  28.                                 line-height: 44px;
  29.                                 margin: 0em;
  30.                                 color: #fff;
  31.                                 margin-left: 100px;
  32.                                 margin-right: 100px;
  33.                                 text-align: center;
  34.                         }
  35.                         #main {
  36.                                 display: -webkit-box;
  37.                                 -webkit-box-orient: vertical;
  38.                                 -webkit-box-pack: center;
  39.                         }
  40.                         a.button {
  41.                                 display: -webkit-box;
  42.                                 -webkit-box-orient: vertical;
  43.                                 -webkit-box-pack: center;
  44.                                 -webkit-box-align: center;
  45.                                 height: 32px;
  46.                                 margin: 8px;
  47.                                 background-color: rgba(240,240,240,1.0);
  48.                                 border-color: rgba(220,220,220,1.0);
  49.                                 border-width: 2px;
  50.                                 border-style: solid;
  51.                         }
  52.                         a.active {
  53.                                 background-color: rgba(240,240,240,0.7);
  54.                         }
  55.                         .input1 {
  56.                                 display: -webkit-box;
  57.                                 -webkit-box-orient: vertical;
  58.                                 -webkit-box-pack: center;
  59.                                 -webkit-box-align: center;
  60.                                 height: 32px;
  61.                                 margin: 8px;
  62.                                 background-color: rgba(240,240,240,1.0);
  63.                                 border-color: rgba(220,220,220,1.0);
  64.                                 border-width: 2px;
  65.                                 border-style: solid;
  66.                         }
  67.                 </style>
  68.         </head>
  69.         <body>
  70.                 <div id="wrap">
  71.                         <div id="main">
  72.                                 <br />
  73.                                 <br />
  74.                                 <br />
  75.                                 <br />
  76.                                 <br />
  77.                                 <a class="button" tapmode="active" onclick="startTimer()">开始定时器</a>
  78.                                 <a class="button" tapmode="active" onclick="stopTimer()">停止定时器</a>
  79.                         </div>
  80.                 </div>
  81.         </body>
  82.         <script type="text/javascript" src="../script/api.js"></script>
  83.         <script>
  84.                 var demo;
  85.                 function startTimer() {
  86.                         demo.startTimer({
  87.                                 step : 1,
  88.                                 isLoop : true
  89.                         }, function(ret, err) {
  90.                                 api.toast({
  91.                                         msg : JSON.stringify(ret) + new Date().getTime()
  92.                                 });
  93.                         });
  94.                 }

  95.                 function stopTimer() {
  96.                         demo.stopTimer(function(ret, err) {
  97.                                 alert(JSON.stringify(ret));
  98.                         });
  99.                 }

  100.                 function apiready() {
  101.                         demo = api.require('myTimer');
  102.                 }
  103.         </script>
  104. </html>
复制代码


33
帖子
0
勋章
226
Y币
安卓熄屏以后 计时器会被回收吗
216
帖子
5
勋章
5909
Y币
你可以试试,,如果系统让app进入后台暂停了。那就不行了
您需要登录后才可以回帖 登录

本版积分规则