J'ai réussit.
J'ai séparé l'initialisation, puis j'ai intégré la fonction du canvas dans mon compteur. Voilà le code JS:
$(function(){
$('input.round').wrap('<div class="round" />').each(function(){
var $input = $(this);
var $div = $input.parent();
$cercle = $('<canvas class="cercle" width="220px" height="220px" />');
$color = $('<canvas class="color" width="220px" height="220px" />');
$div. append($cercle);
$div. append($color);
});
function Init_temps(){
var jours = $('input#jours');
var heures = $('input#heures');
var minutes = $('input#minutes');
var secondes = $('input#secondes');
var now = new Date();
var finale = new Date ("April 9 15:15:15 2013");
var sec = (finale - now) / 1000;
var n = 24 * 3600;
if (sec > 0) {
j = Math.floor (sec / n);
h = Math.floor ((sec - (j * n)) / 3600);
mn = Math.floor ((sec - ((j * n + h * 3600))) / 60);
sec = Math.floor (sec - ((j * n + h * 3600 + mn * 60)));
jours.val(j);
heures.val(h);
minutes.val(mn);
secondes.val(sec);
}
}
function Affichage(){
$('input.round').each(function(){
var $input = $(this);
var $div = $input.parent();
var min = $input.data('min');
var max = $input.data('max');
$cercle = $div.children('.cercle');
$color = $div.children('.color');
console.log('Init : '+$input.attr('id')+' '+$color.toSource());
var ctx = $cercle[0].getContext('2d');
ctx.clearRect(0,0,220,220);
ctx.beginPath();
ctx.arc(110,110,95,0,2*Math.PI);
ctx.lineWidth = 20;
ctx.strokeStyle = "#fff";
ctx.shadowOffsetX = 2;
ctx.shadowBlur = 5;
ctx.shadowColor = "rgba(0,0,0,0.2)";
ctx.stroke();
var ratio = ($input.val() - min) / (max - min);
var ctx = $color[0].getContext('2d');
ctx.clearRect(0,0,220,220);
ctx.beginPath();
ctx.arc(110,110,95,-1/2 * Math.PI, ratio*2*Math.PI - 1/2 * Math.PI);
ctx.lineWidth = 20;
ctx.strokeStyle = "#2DA2C5";
ctx.stroke();
});
}
Init_temps();
Affichage();
Rebour();
function Rebour() {
Init_temps();
Affichage();
window.setTimeout (Rebour, 1000);
}
});