2016-09-13 3 views
0

jQuery에서이 카운트 다운이 있지만 월 및 일에 올바른 숫자가 표시되지 않습니다. 오류가 달과 일의 계산에 있습니다jquery 카운트 다운 년 월 일

seconds/(60 * 60 * 24 * 30.41666666 * 12) 

이 JQuery와 있습니다 :

(function($) { 

$.fn.countdown = function(options, callback) { 

var settings = { 'date': null } 

if (options) { 
    $.extend(settings, options) 
} 

this_sel = $(this); 

function count_ecec() { 
    eventDate = Date.parse(settings['date'])/1000; 
    currentDate = Math.floor($.now()/1000); 

    if (eventDate <= currentDate) { 
    callback.call(this); 
    clearInterval(interval); 
    } 

    seconds = eventDate - currentDate; 

    if (this_sel.find('.years').length > 0) { 
    years = Math.floor(seconds/(60 * 60 * 24 * 30.41666666 * 12)); 
    seconds -= years * 60 * 60 * 24 * 30.41666666 * 12 ; 
    } 

    if (this_sel.find('.days').length > 0) { 
    days = Math.floor(seconds/(60 * 60 * 24 * 30.41666666)); 
    seconds -= days * 60 * 60 * 24 * 30.41666666; 
} 
    if (this_sel.find('.month').length > 0) { 
    month = Math.floor(seconds/(60 * 60 * 24)); 
    seconds -= month * 60 * 60 * 24 ; 
} 
    if (!isNaN(eventDate)) { 
    if (this_sel.find('.years').length > 0) { 
     this_sel.find('.years').text(years); 
    } 
    if (this_sel.find('.days').length > 0) { 
    this_sel.find('.days').text(days); 
    } 
    if (this_sel.find('.month').length > 0) { 
    this_sel.find('.month').text(month); 
    } 
    } 
} 
count_ecec(); 
interval = setInterval(count_ecec, 1000); 
} 

}) (jQuery); 

그리고 이것은 HTML입니다 :

<div class="large-5 large-centered columns counter">      
      <div class="container"> 
       <div id="countdown"> 
       <div class="large-4 columns"> 
        <span>Día</span> 
        <span class="days"></span> 
       </div> 
       <div class="large-4 columns"> 
        <span>Mes</span> 
        <span class="month"></span> 
       </div> 
       <div class="large-4 columns"> 
        <span>Año</span> 
        <span class="years"></span> 
       </div> 
       </div> 
      </div> 
      </div> 

<script src="js/countdown.js" charset="utf-8"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $('#countdown').countdown({date: '15/12/2016'}, function() { 
    $('#countdown').text(''); 
    }); 
}); 
</script> 

답변

1

난 당신이 방정식을 생각 며칠 동안 플립 플립 ....

days = Math.floor(seconds/(60 * 60 * 24 * 30.41666666)); 

이어야합니다.
months = Math.floor(seconds/(60 * 60 * 24 * 30.41666666)); 
+0

완벽하게 작동해야합니다. –