微信小程序中活动倒计时的效果怎样做?
Admin 2021-10-28 群英技术资讯 1549 次浏览
微信小程序中活动倒计时的效果怎样做?倒计时的功能应用场景有很多,例如答题倒计时,商城活动倒计时等等,这里我们主要来接微信小程序中活动倒计时功能的实现,有一定的参考价值,感兴趣的朋友就继续往下看吧。
商城商品中的活动倒计时
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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
在之前的文章《JS循环学习:while循环语句的使用(示例详解)》中,我们简单了解了 while 循环和 do while 循环,而今天再来介绍一种循环——for 循环语句,希望对大家有所帮助!
需求:后端返回全部列数据。前端根据选项来显示对应的列,如果不勾选,默认全部隐藏。效果图勾选后显示对应的列上代码html部分这里用v-if来显示隐藏,因为这个elementul组件的原因,v-show不生效,要用v-ifel-table-column v-if=lists[0].ispass
本文实例为大家分享了vue实现列表垂直无缝滚动的具体代码,供大家参考,具体内容如下实现新闻列表的轮播(如下图)上代码封装的so-marquee.vuetemplate div class=marquee-wrapper :style={ width: realWidth + px }
js如何去除数组中的empty undefined空项 目录 去除数组中的empty undefined空项 去掉数组中无效的值,比如null,undefined,empty 方法一 方法二 去除数组中的empty undefined空项 arr.filter(d=>d) 注意,0也会被去掉 去掉数组中无效的值,比如null,undefined,empty 方法一 直接使用filter就能搞定了 var arr=[1,2,null,undefined,9]; arr=arr.filter(Boolean); 结果arr=[1,2,9] 方法二 ...
使用组件库时,图标往往不能满足需求,所以我们常常需要用到第三方图标库,这篇文章主要给大家介绍了关于vue引入iconfont的相关资料,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008