富贵资源网 Design By www.hznty.com

本文实例为大家分享了jquery做一个小的倒计时效果的代码,供大家参考,具体内容如下

html:

<div id="shop_rec">
 <ul class="cf">
  <li>
   <img src="/UploadFiles/2021-04-02/goods.jpg">

jquery:

$(function(){
 var abj = $("#shop_rec"),
  timeObj = abj.find('.time');
 var starttime = timeObj.data('starttime');

 // 定时器函数
 function actionDo(){
  return setInterval(function(){
   timeObj.each(function(index, el) {
    var t = $(this),
     surplusTime = t.data('endtime') -starttime;
    if (surplusTime <= 0) {
     t.html("活动已经开始");
    } else{
     var year = surplusTime/(24*60*60*365),
      showYear = parseInt(year),
      month = (year-showYear)*12,
      showMonth = parseInt(month),
      day = (month-showMonth)*30,
      showDay = parseInt(day),
      hour = (day-showDay)*24,
      showHour = parseInt(hour),
      minute = (hour-showHour)*60,
      showMinute = parseInt(minute),
      seconds = (minute-showMinute)*60,
      showSeconds = parseInt(seconds);
     t.html("");
     if (showYear>0) {
      t.append("<span>"+showYear+"年</span>")
     };
     if (showMonth>0) {
      t.append("<span>"+showMonth+"月</span>")
     };
     if (showDay>0) {
      t.append("<span>"+showDay+"天</span>")
     };
     if (showHour>=0) {
      t.append("<span>"+showHour+"小时</span>")
     };
     if (showMinute>=0) {
      t.append("<span>"+showMinute+"分钟</span>")
     };
     if (showSeconds>=0) {
      t.append("<span>"+showSeconds+"秒</span>")
     };
    };
   });
   starttime++;
  },1000); // 设定执行或延时时间
 };
 // 执行它
 actionDo();
});

本文由FungLeo原创

本文地址:http://blog.csdn.net/fungleo/article/details/49446887

总结

不是特别优秀,但是小的应用完全没有问题。

精彩专题分享:js实现倒计时功能汇总

以上就是本文的全部内容,希望对大家的学习有所帮助。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com