2012-03-07 22 views
1

[OK]をので、私はjquery countdown pluginを使用していますが、宣言はカウンタ30秒ごとにReseting

$j(document).ready(function() { 
$j('#clock').countdown({ to : "#{event.start_date.strftime("%Y:%m:%d:%H:%M")}", remaining : "#{event.start_date - Time.now}", display_on_complete : 'list', hide_on_complete : 'countdown' }); 
}); 

を下回っている、これは正常に動作しますが、私はこのAJAX呼び出し

から時間の経過と共にこのカウントダウンを更新する必要があり、30秒ごとに
$j(document).ready(function() { 
    function refresh() { 
    $j.ajax({ 
    type: "GET", 
    url: "http://developer.yahooapis.com/TimeService/V1/getTime?appid=YahooDemo&output=json", 
    dataType: "jsonp", 
    success: function(data){ 
    unix_timestamp = data.Result.Timestamp 
    var json_date = new Date(unix_timestamp*1000); 
    console.log(json_date); 
    setTimeout(refresh, 30000); 
    } 
}); 

あなたは...日付がjson_date変数です.....そして私は30秒ごとにカウントダウン方式でTime.nowを交換する必要があり、この

+0

refresh()関数を内部のどこからでも呼び出すことはありませんか?ループしたいと思っていますが、それを初期化したようには見えません。 –

+0

私はあなたのコードに問題はない、唯一の可能性のある問題はコンテキストかもしれません。あなたの関数を 'window.refresh = function(){...};'として定義し、物事が異なっているかどうかを調べてみてください。また、あなたのコードに '});のセットがありません。 – rkw

答えて

2

を達成するためにどのように任意のアイデアを見ることができるようにjQuery-countdown-Timerプラグインは、任意の残り時間の設定をサポートしていません。

また、プラグインではオプションとしてremainingは使用されません。 (display_on_completeまたはhide_on_complete`オプションもありません。間違ったプラグインにリンクしている場合はお知らせください)

プラグインに任意の残り時間を持たせたい場合は、プラグイン。

私はjquery.countdown-timer.jsの42〜50行を変更したい:

if (options.remaining) { 
    seconds_remaining = options.remaining; 
} else { 
    // Split the specified date/time string into an array 
    var date_elements = options.to.split(':'); 

    // Create Date objects for start and end date/times 
    var end_date = new Date (date_elements[0], date_elements[1] - 1, date_elements[2], date_elements[3], date_elements[4]); 
    var start_date = new Date(); 

    // Calculate number of seconds remain until end date/time 
    seconds_remaining = (end_date.getTime() - start_date.getTime()) * .001; 
} 

そして、あなたのAJAX呼び出し内の道を、次のカウントダウン機能を呼び出します。

function refresh() { 
    $j.ajax({ 
     type: "GET", 
     url: "http://developer.yahooapis.com/TimeService/V1/getTime?appid=YahooDemo&output=json", 
     dataType: "json", // your url doesn't have a callback, no need for jsonp 
     success: function(data){ 
      unix_timestamp = data.Result.Timestamp 
      var json_date = new Date(unix_timestamp*1000); 

      $j('#clock').countdown({ remaining: (event.start_date - json_date) * .001 }); 

      setTimeout(refresh, 30000); 
     } 
    }); 
} 

これはeventオブジェクトと仮定していますがrefresh関数の範囲内にあり、$jがjQueryオブジェクトです。

私は完全にあなたの質問を誤解している可能性がありますので、私は私に知らせてください。

+0

私はそれが変更されている可能性があります...ここにリンクhttp://pastie.org/3541077です – Trace

関連する問題