微信小程序之倒计时插件   wxTimer

介绍:

  用于在微信小程序中进行倒计时的组件。

功能:

  1、最基础的当然就是倒计时功能了。
  2、可以设置倒计时结束后执行的事件。
  3、可以设置倒计时执行过程中每隔多少秒,执行一次对应的事件。

下载: wxTimer

在JS中调用

1.在当前js引入 
timer = require('../../plug/wxTimer.js')
  2.在全局app.js引入

  app.js

globalData: {
userInfo: null,
timer: require('/plug/wxTimer.js')
}

  当前js

var app = getApp().globalData,
timer = app.timer;
最简单的调用方式:
var wxTimer = new timer({
beginTime:"00:00:10"
})
wxTimer.start(this);
wxTimer.stop();
开启多个计时
//开启第一个定时器
var wxTimer1 = new timer({
beginTime:"00:00:10",
name:'wxTimer1',
complete:function(){
console.log("完成了")
}
})
wxTimer1.start(this); //开启第二个定时器
var wxTimer2 = new timer({
beginTime:"00:01:11",
name:'wxTimer2',
complete:function(){
console.log("完成了")
}
})
wxTimer2.start(this);
倒计时结束后执行事件
var wxTimer = new timer({
beginTime:"00:00:10",
complete:function(){
console.log("完成了")
}
})
wxTimer.start(this);
间隔执行事件
var wxTimer = new timer({
beginTime:"00:00:10",
complete:function(){
console.log("完成了")
},
interval:,
intervalFn:function(){
console.log("过去了2秒");
}
})
校准时间
wxTimer.calibration();
结束计时
wxTimer.stop();

在wxml中引用

单个计时器:
<view>显示剩余时间:{{wxTimer}}</view>
<view>显示剩余秒数:{{wxTimerSecond}}</view>
多个计时器:
<view>显示计时器1的剩余时间:{{wxTimerList['wxTimer1'].wxTimer}}</view>
<view>显示计时器2的剩余时间:{{wxTimerList['wxTimer2'].wxTimer}}</view>
<view>显示计时器1的剩余秒数:{{wxTimerList['wxTimer1'].wxTimerSecond}}</view>
<view>显示计时器2的剩余秒数:{{wxTimerList['wxTimer2'].wxTimerSecond}}</view>

注意:

   1、由于内部需要调用到小程序的setData方法,所以我们需要把this传过去。
  2、此方法会在page中生成一个名为wxTimer,wxTimerSecond和wxTimerList的数据,请保证这些key没有被占用 3、请在data中添加一条属性wxTimerList:{},否则将会报错。

其他参数:

   1、beginTime 需要倒计时的时间,比如:"01:11:12",默认值为"00:00:00",也可以省略秒数,如:"01:10"

  2、complete 倒计时归零0时的回调函数,如果为beginTime = "00:00:00"则立即调用

  3、interval 倒计时的过程中,规定每隔几秒执行一次intervalFn,如果为0则永远不会执行,默认为1

  4、intervalFn 每隔interval秒执行一次的函数。

微信小程序之倒计时插件 wxTimer的更多相关文章

  1. 微信小程序的wx-charts插件-tab选项卡

    微信小程序的wx-charts插件-tab选项卡 效果: //index.js var wxCharts = require('../../utils/wxcharts-min.js'); const ...

  2. Fundebug微信小程序错误监控插件更新至1.1.0,新增test()与notifyHttpError()方法

    摘要: 1.1.0新增fundebug.test()和fundebug.notifyHttpError()方法,同时大小压缩至15K. Fundebug是专业的小程序BUG监控服务,可以第一时间为您捕 ...

  3. 微信小程序的wx-charts插件

    还有就是可以使用一些小程序的插件,比如wx-charts. 先来看一下网上对这个插件的评价: 目前在github上有1804颗星,使用的比较广泛. github地址:https://github.co ...

  4. 解决微信小程序的wx-charts插件tab切换时的显示会出现位置移动问题-tab切换时,图表显示错乱-实现滑动tab

    解决Echarts在微信小程序tab切换时的显示会出现位置移动问题 tab切换时,图表显示错乱 <canvas class="kcanvas" canvas-id=" ...

  5. 微信小程序 - 考试倒计时

    源码如下(csdn提供了思路 , 多谢 ,第二个小程序项目,有惊无险(_._): Page({ /** * 页面的初始数据 */ data: { timer: '', //定时器名字 countDow ...

  6. 微信小程序的自定义插件

    第一步,创建一个页面和普通页面一样 第二不,在这个页面上进行对json配置, "component":true 第三不在需要插入的页面中进行设置 插入标签 <dialog i ...

  7. 微信小程序单个倒计时效果

    var end_time = grouponList.expire_time.replace(/-/g, '/') grouponcountdown(that, end_time) //适用于商品列表 ...

  8. 【微信小程序】日历插件,适用于酒店订房类小程序

    本插件在原作者(传送门:http://blog.csdn.net/lengyue1084/article/details/71248778)基础上升级. 增加了点击选择具体日期和数据传输功能. 效果图 ...

  9. 微信小程序 列表倒计时

    最近要实现一个列表倒计时的功能,写了个demo 展示图 <view class="center colu"> <view class="time&quo ...

随机推荐

  1. HDU 3172 Virtual Friends (map+并查集)

    These days, you can do all sorts of things online. For example, you can use various websites to make ...

  2. How to solve the problem that BMW Icom A2 A3 host can’t be connected?

    Aftre the BMW ICOM host is connected to the car via a 16PIN connector, and the other side is connect ...

  3. Java用Gson遍历json所有节点

    <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</ar ...

  4. SRTP参数及数据包处理过程(转)

    源: SRTP参数及数据包处理过程

  5. pandas 应用

    类似vlookup import pandas as pd file = pd.read_csv('NIN411PF.CSV', encoding='ANSI') a = pd.DataFrame({ ...

  6. 如何使用 lsyncd 实时同步并执行 shell 命令

    修改 lsyncd 的默认配置,不直接执行rsync 进行同步,而是改用自己的脚本. binary 指定我们的脚本 vim /usr/local/lsyncd/etc/lsyncd.conf sett ...

  7. fjwc2019 D6T1 堆(组合数+打表)

    #193. 「2019冬令营提高组」堆 但是每个点都遍历一遍,有些点的子树完全相同却重复算了 忽然记起完全二叉树的性质之一:每个非叶节点的子树中至少有一个是满二叉树 那么我们预处理满二叉树的那一块,剩 ...

  8. fjwc2019 D2T1 直径 (构造)

    #181. 「2019冬令营提高组」直径 (这题构造题是我考场上唯一一A的题........) 先看这个特殊的Subtask4 Subtask 4(20pts):$\sqrt{1+8k}$​​​ 为整 ...

  9. Linux Redhat 安装免费yum源

    Linux Redhat 安装免费yum源 出处地址:http://www.cnblogs.com/nbartchen/p/8565816.html 1.查看是否安装相关包 rpm -qa|grep ...

  10. AngularJs 开发遇到的问题,以及解决方案

    1>ng-if 导致 ng-model 失效的问题 比如说下拉联动隐藏显示的时候,多个验证模块,需要使用到ng-if.可以使用 $parent 来解决这个问题 ng-model="$p ...