商城商品倒计时原生插件

Posted 从你世界路过

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了商城商品倒计时原生插件相关的知识,希望对你有一定的参考价值。

 
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/jquery.min.js"></script>
    </head>

    <body>
        <div id="p1"></div>
        <div id="p2"></div>
        <script>
            var i = 0;
            function DownTime(StartTime, EndTime, CurrentTime, callback) {

                //计算器
                this.couputer = function(StatTime, EndTime, type) {
                    var EndTime = new Date(EndTime);
                    var NowTime = new Date(StatTime);
                    NowTime = new Date(NowTime.getTime() + 1000 * i);
                    var t = EndTime.getTime() - NowTime.getTime();
                    var d = 0;
                    var h = 0;
                    var m = 0;
                    var s = 0;
                    if(t >= 0) {
                        d = Math.floor(t / 1000 / 60 / 60 / 24);
                        h = Math.floor(t / 1000 / 60 / 60 % 24);
                        m = Math.floor(t / 1000 / 60 % 60);
                        s = Math.floor(t / 1000 % 60);
                    }
                    var Time = {

                        d: d,
                        h: h,
                        m: m,
                        s: s

                    }
                    if(type == 0) {

                        Time.title = out;
                        //                        clearTimeout(Timer)

                    } else if(type == 1) {

                        Time.title = wait;

                    } else if(type == 2) {

                        Time.title = end;
                    }
                    var time = d + "" + h + "" + m + "" + s + "" + Time.title;

                    callback(Time);
                };
                var self = this;
                this.init = function(StartTime, EndTime, CurrentTime) {

                    if(self.judge1(StartTime, CurrentTime)) {

                        //距离抢购时间倒计时
                        self.couputer(CurrentTime, StartTime, 1);

                    } else {

                        if(self.judge2(CurrentTime, EndTime)) {

                            //距离抢购时间倒计时
                            self.couputer(CurrentTime, EndTime, 2);
                        } else {
                            //结束抢购
                            self.couputer(CurrentTime, EndTime, 0);
                        }

                    }
                }
                this.init(StartTime, EndTime, CurrentTime);

            }
            //活动结束
            DownTime.prototype.judge1 = function(StartTime, CurrentTime) {

                StartTime = new Date(StartTime.replace(/\-/g, "\/"));
                CurrentTime = new Date(CurrentTime.replace(/\-/g, "\/"));
                CurrentTime = new Date(CurrentTime.getTime() + 1000 * i);
                if(StartTime > CurrentTime) {

                    return true;
                }

                return false;
            }

            //开始抢购
            DownTime.prototype.judge2 = function(CurrentTime, EndTime) {

                CurrentTime = new Date(CurrentTime.replace(/\-/g, "\/"));
                EndTime = new Date(EndTime.replace(/\-/g, "\/"));
                CurrentTime = new Date(CurrentTime.getTime() + 1000 * i);
                if(EndTime > CurrentTime) {

                    return true;
                }
                return false;
            }

            function GetBuying() {
                  
                new DownTime("2017/12/22 15:00:08", "2017/12/22 17:00:10", "2017/12/22 16:59:58", function(ret) {
                      console.log(ret)
                });
                new DownTime("2017/12/22 17:00:08", "2017/12/22 22:00:10", "2017/12/22 16:59:58", function() {

                });
                i++;
            }
            var Timer = setInterval(GetBuying, 1000)
        </script>
    </body>

</html>
拿走不谢

 

以上是关于商城商品倒计时原生插件的主要内容,如果未能解决你的问题,请参考以下文章

ShopNC Android 好商城原生安卓客户端源码项目

如何实现React原生倒计时圈

将以下jq代码转换为原生js

wordpress 怎么建设商城网站

EC 优易软件 跨境购V3 商城模板 2018跨境商城

淘淘商城的第一天