search
HomeWeChat AppletMini Program DevelopmentWeChat applet dynamically displays project countdown effect

WeChat applet dynamically displays project countdown effect

Jun 23, 2018 pm 05:10 PM
CountdownWeChat applet

This article mainly introduces the WeChat applet dynamic display project countdown in detail. The format is such as 4 days, 7 hours, 58 minutes and 39 seconds. It has certain reference value. Interested friends can refer to it

The example in this article shares with you the specific code for dynamically displaying the countdown of the project in the WeChat applet for your reference. The specific content is as follows

1. Generally, when we talk about displaying flash sales, it refers to a single piece of data. I don’t have a loop. Do.

Effect:

2. wxml code:

<p>
<block wx:if="{{total_micro_second<=0}}">剩余时间:已经截止</block>
<block wx:if="{{clock!=&#39;已经截止&#39;}}">剩余时间:{{clock}}</block>
</p>

3. js file code:

function countdown(that) {
 var EndTime = that.data.end_time || [];
 var NowTime = new Date().getTime();
 var total_micro_second = EndTime - NowTime || [];
 console.log(&#39;剩余时间:&#39; + total_micro_second);
  // 渲染倒计时时钟
  that.setData({
  clock: dateformat(total_micro_second)
  });
  if (total_micro_second <= 0) {
  that.setData({
   clock: "已经截止"
  });
  //return;
  }
  setTimeout(function () {
  total_micro_second -= 1000;
  countdown(that);
  }
  , 1000)
 }

 // 时间格式化输出,如11:03 25:19 每1s都会调用一次
 function dateformat(micro_second) {
  // 总秒数
  var second = Math.floor(micro_second / 1000);
  // 天数
  var day = Math.floor(second/3600/24);
  // 小时
  var hr = Math.floor(second/3600%24);
  // 分钟
  var min = Math.floor(second/60%60);
  // 秒
  var sec = Math.floor(second%60);
  return day + "天" + hr + "小时" + min + "分钟" + sec+"秒";
 }

Page({

 /**
 * 页面的初始数据
 */
 data: {
 id:&#39;&#39;,
 result:[],
 end_time:&#39;&#39;,
 clock:&#39;&#39;
 },/**
 * 生命周期函数--监听页面加载
 */
 onLoad: function (options) {
 var that = this;
 wx.request({
  url: &#39;https://m.******.com/index.php/Home/Xiaoxxf/activity_detail?a_id=&#39;+options.id,//不含富文本html
  data: {},
  method: &#39;GET&#39;, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  header: {
  &#39;Content-Type&#39;: &#39;application/json&#39;
  },
  success: function (res) {
  that.setData({
   common: res.data, //一维数组,全部数据
   end_time: res.data.end_time //项目截止时间,时间戳,单位毫秒
  })
  console.log(that.data.common);
  console.log(&#39;结束时间:&#39; + that.data.end_time);
  },
  fail: function (res) { },
  complete: function (res) { },
 }), 
//调用上面定义的递归函数,一秒一刷新时间
 countdown(that);
},

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

WeChat Mini Program How to use setData

How to use the WeChat applet date and time selector

WeChat applet network request Carousel image

The above is the detailed content of WeChat applet dynamically displays project countdown effect. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),