1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| $(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);
}
}); |
Partager