微信小程序中活动倒计时的效果怎样做?
Admin 2021-10-28 群英技术资讯 1102 次浏览
微信小程序中活动倒计时的效果怎样做?倒计时的功能应用场景有很多,例如答题倒计时,商城活动倒计时等等,这里我们主要来接微信小程序中活动倒计时功能的实现,有一定的参考价值,感兴趣的朋友就继续往下看吧。
商城商品中的活动倒计时
js
var endTime = new Date().getTime() + 24 * 3600 * 1000*4;
Page({
/**
* 页面的初始数据
*/
data: {
headerImgs: postData.postSwiperData,
countDownDay: '',
countDownHour: '',
countDownMinute: '',
countDownSecond: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var id = options.id; //页面跳转传过来的值
},
onReady: function() {
var that = this;
countdown(that);
}
})
function countdown(that) {
var NowTime = new Date().getTime();
var EndTime = endTime;
var total_micro_second = EndTime - NowTime || [];
console.log('当前时间'+NowTime+'\n剩余时间:' + total_micro_second);
// 渲染倒计时时钟
that.setData({
countDownDay: dateformaDay(total_micro_second),
countDownHour: dateformaHour(total_micro_second),
countDownMinute: dateformaMinute(total_micro_second),
countDownSecond: dateformaSecondMinute(total_micro_second),
});
// if (total_micro_second <= 0) {
// that.setData({
// clock: "已经截止"
// });
// //return;
// }
setTimeout(function() {
total_micro_second -= 1000;
countdown(that);
}, 1000)
}
// 时间格式化输出
function dateformaDay(micro_second) {
// 总秒数
var second = Math.floor(micro_second / 1000);
// 天数
var day = Math.floor(second / 3600 / 24);
return day;
}
function dateformaHour(micro_second) {
// 总秒数
var second = Math.floor(micro_second / 1000);
// 小时
var hr = Math.floor(second / 3600 % 24);
return hr;
}
function dateformaMinute(micro_second) {
// 总秒数
var second = Math.floor(micro_second / 1000);
// 分钟
var min = Math.floor(second / 60 % 60);
return min;
}
function dateformaSecondMinute(micro_second) {
// 总秒数
var second = Math.floor(micro_second / 1000);
// 秒
var sec = Math.floor(second % 60);
return sec;
}
wxml
<!-- 倒计时 start -->
<view style='display:flex;flex-direction:column;'>
<span style="font-size:10px;color:white;margin-top:5px;">距活动结束还剩</span>
<view class='time-container'>
<text class='time-number'>{{countDownDay}}</text>
<span class='time-text'>天</span>
<text class='time-number'>{{countDownHour}}</text>
<span class='time-text'>时</span>
<text class='time-number'>{{countDownMinute}}</text>
<span class='time-text '>分</span>
<text class='time-number '>{{countDownSecond}}</text>
<span class='time-text '>秒</span>
</view>
</view>
<!-- 倒计时 end -->
wxss
.time-container {
display: flex;
flex-direction: row;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
align-items: center;
}
.time-number {
background: white;
color: red;
width: 18px;
height: 18px;
font-size: 12px;
border-radius: 3px;
display: flex;
align-items: center;
justify-content: center;
}
.time-text {
font-size: 10px;
color: white;
margin: 3px;
}
关于微信小程序倒计时功能的实现就介绍到这,这里只是分享了一种实现倒计时功能的方法,希望本文对大家学习或者功能能有帮助,想要了解更多大家可以关注其它的相关文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家详细介绍了微信小程序实现手写板,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了从react hooks闭包陷阱切入浅谈react hooks,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
这篇文章主要为大家详细介绍了原生JS实现翻书特效,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了JavaScript实现移动端签字功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了Node.js的概念和基本原理,对Node.js感兴趣的同学,一定要看一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008