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

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

高洛峰
Release: 2017-02-27 14:17:52
Original
3085 people have browsed it

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>
Copy after login

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 ;  
   }
Copy after login


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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template