Home  >  Article  >  WeChat Applet  >  Realize the effect of e-commerce flash sale countdown in mini program

Realize the effect of e-commerce flash sale countdown in mini program

高洛峰
高洛峰Original
2017-02-27 14:17:523069browse

In e-commerce applications, flash sales are often used, and the flash sales will have a countdown function. Here we use the countdown function we showed you last time in e-commerce applications.


Basic implementation functions
1, the mini program imitates the e-commerce website flash kill countdown
2, the display format is: for example, 1 day 11 hours, 11 minutes, 11 seconds 11
3, flash kill After the time is up, it will prompt that the flash sale is over


Look at the renderings first

Realize the effect of e-commerce flash sale countdown in mini program

Realize the effect of e-commerce flash sale countdown in mini program

##In fact, the implementation is quite simple

<span style="font-size:18px;"><!--index.wxml--> 
<view class="container">  
<text >秒杀: {{clock}}</text>  
<text>{{micro_second}}</text>  
</view></span>

The following is the js implementation code

<span style="font-size:18px;">// indes.js  
/**   
 * 需要一个目标日期,初始化时,先得出到当前时间还有剩余多少秒  
 * 1.将秒数换成格式化输出为XX天XX小时XX分钟XX秒 XX  
 * 2.提供一个时钟,每10ms运行一次,渲染时钟,再总ms数自减10  
 * 3.剩余的秒次为零时,return,给出tips提示说,已经截止  
 */ 
    
// 定义一个总毫秒数,以一天为例  
// var total_micro_second = 3600 * 1000*24;//这是一天倒计时  
var total_micro_second = 10 * 1000;//这是10秒倒计时  
    
/* 毫秒级秒杀倒计时 */ 
function countdown(that) {  
   // 渲染倒计时时钟  
   that.setData({  
     clock:dateformat(total_micro_second)//格式化时间  
   });  
    
   if (total_micro_second <= 0) {  
     that.setData({  
       clock:"秒杀结束" 
     });  
     // timeout则跳出递归  
     return ;  
   }


For more mini programs to achieve the effect of e-commerce flash sale countdown, please pay attention to the PHP Chinese website for related articles!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn