


Realize the effect of e-commerce flash sale countdown in mini program
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
<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 ; }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)