codecamp

小程序自学系列(零基础学小程序001)---小程序实现简单的倒计时效果

基本实现功能

1,从60到0的倒计时效果

2,倒计时完毕后会有提示


先看效果图



其实实现代码很简单

<!--index.wxml-->
<view class="container">
 <text>倒计时: {{second}} </text>
</view>


下面是相对应得js处理

//index.js
// 从从60到到0倒计时
function countdown(that) {
 var second = that.data.second
 if (second == 0) {
  that.setData({
   second: "60秒倒计时结束"
  });
  return ;
 }
 var time = setTimeout(function(){
  that.setData({
   second: second - 1
  });
  countdown(that);
 }
 ,1000)
}
 
Page({
  data: {
    second: 60
  },
  onLoad: function() {
    countdown(this);
  }
});

源码地址:http://download.csdn.net/detail/qiushi_1990/9692072

更多微信小程序优秀源码:https://github.com/qiushi123/xiaochengxu_demos

也可以关注我的个人微信号,每天定期推送小程序最新开发技术,优秀源码,各种干货

有问题加我微信:2501902696(备注小程序)

小程序自学系列(零基础学小程序002)---小程序实现电商秒杀倒计时效果
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }