小程序(倒计时的制作)
- 小程序(倒计时的制作) 推荐度:
- 相关推荐
小程序(倒计时的制作)
小程序(倒计时的制作)
微信小程序如火如荼,今天我借教程做一篇倒计时效果的小程序页面.
这样的效果是怎样实现的呢
按以下步骤操作
wxml文件放个text:
<view><text>{{second}} 秒:{{micro_second}}</text>
</view>
然后在js文件下编写如下代码:
function countdown(that) {var second = that.data.second if (second == 0) { // console.log("时间到...");that.setData({second: "Time Out..."}); return;} var time = setTimeout(function () {that.setData({second: second - 1});countdown(that);}, 1000)
}
在Page里面加入:
second: 3,
在onLoad加载函数里面执行倒计时函数:
countdown(this);
最终效果如图:
加入毫秒demo
更改js代码:
function countdown(that) {var second = that.data.second if (second == 0) {that.setData({second: "时间到!",micro_second: " " ,s:0});clearTimeout(micro_timer);return;}var timer = setTimeout(function () {that.setData({second: second - 1});countdown(that);} , 1000)
}
/* 毫秒级倒计时 */
// 初始毫秒数,同时用作归零
var micro_second_init = 100;
// 当前毫秒数
var micro_second_current = micro_second_init;
// 毫秒计时器
var micro_timer;
function countdown4micro(that) { if (micro_second_current <= 0) {micro_second_current = micro_second_init;}
micro_timer = setTimeout(function () {that.setData({micro_second: micro_second_current - 1});micro_second_current--;countdown4micro(that);
}, 10)
}
在onload函数如加入上述的两个计时函数:
countdown(this);countdown4micro(this);
最终效果:
最新文章
- 【Delphi学习】Form的borderstyle属性
- 俞敏洪一分钟励志演讲:
- “脱离应用开发者的数据库,不会成功”,黄东旭万字长文剖析数据库发展新趋势...
- json php 传输,使用JSON实现数据的跨域传输的php代码
- 哀悼日, 网页变灰的实现
- 用JS 控制文字两行 ,展示省略号(兼容谷歌 IE等各大浏览器)
- 02195511
- mmap优缺点
- vss服务器的简单使用
- vss命令行的使用
- CruiseControl.Net学习记录
- ext2与ext3的区别
- C++,VC资源
- HashTable 使用
- Java Integer值范围问题
- https双向加密认证
- PyQt5数据库开发2 5.1 QSqlQueryModel