Javascript - 将countDown计时器更改为countUp time

时间:2017-03-02 18:10:33

标签: javascript counter

我有和html计算了我的活动的日子,现在活动已经结束,柜台显示作为负数的日子。如何使现有的JS代码计数。我是学习HTML和js的新手,非常感谢你的知识。

以下是来自外部链接JS文件的代码:



/*-----Countdown timer created by webnesters.com-------*/
jQuery.fn.CountingDown = function(options) {
	var settings = jQuery.extend({
		'date': null
	},
	options );
	myp=jQuery(this);
	function calculate_time(){
		var future = Date.parse(settings[
			'date'
		]);
    var now = new Date();
	
    var difference = Math.floor((future - now) / 1000);
    var seconds = chkinteger(difference % 60);
	
    difference = Math.floor(difference / 60);
    var minutes = chkinteger(difference % 60);
	
    difference = Math.floor(difference / 60);
    var hours = chkinteger(difference % 24);
	
    difference = Math.floor(difference / 24);
    var days = difference;

	if(days.toString().length==1){
		days='0'+days;
	}
    myp.find("#seconds").text(seconds);
    myp.find("#minutes").text(minutes);
   	myp.find("#hours").text(hours);
   	myp.find("#days").text(days);
	}
	
	function chkinteger(integer)
	{
		if (integer < 0)
        integer = 0;
    if (integer < 10)
        return "0" + integer;
    return "" + integer;
	}
	calculate_time();
	interval = setInterval(calculate_time,1000);
};
&#13;
&#13;
&#13;

以下是HTML中的代码:

<h4>12 november 2016</h4>

            <div class="countdown-container" id="countdown">
                <div class="countdown-box-wrap-year">
                    <div class="countdown-box">
                        <div class="countdown-box-border-year">
                        </div>
                                            <div class="countdown-box-border-year2">
                        </div>

                        <span id="days">00</span>
                    </div>
                    <strong>Days</strong>
                </div>
                <div class="countdown-box-wrap">
                    <div class="countdown-box">
                        <div class="countdown-box-border">
                        </div>
                        <span id="hours">00</span>
                    </div>
                    <strong>Hours</strong>
                </div>
                <div class="countdown-box-wrap">
                    <div class="countdown-box">
                        <div class="countdown-box-border">
                        </div>
                        <span id="minutes">00</span>
                    </div>
                    <strong>Minutes</strong>
                </div>
                <div class="countdown-box-wrap">
                    <div class="countdown-box">
                        <div class="countdown-box-border">
                        </div>
                        <span id="seconds">00</span>
                    </div>
                    <strong>Seconds</strong>
                </div>
            </div>
             <script type="text/javascript">
             jQuery(document).ready(function(){
                jQuery("#countdown").CountingDown({
                    date: "12 november 2016 14:00:00"  // Enter your countdown date and time
                });
            });
 </script>

1 个答案:

答案 0 :(得分:0)

这一行:

var difference = Math.floor((future - now) / 1000);

变为:

var difference = Math.floor((now - future) / 1000);

发生了什么?我们 花费时间直到将来的日期(未来减去现在=剩余的时间)。

我们现在想要时间那个日期(现在减去未来 [顺便说一下现在已经过去] =时间过去了。)