script type text javascript window onload function function startTimer

 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
?><script type="text/javascript">
window.onload = function(){
function startTimer() {
var my_timer = document.getElementById("my_timer");
var time = my_timer.innerHTML;
var arr = time.split(":");
var h = arr[0];
var m = arr[1];
var s = arr[2];
if (s == 0) {
if (m == 0) {
if (h == 0) {
document.getElementById("game").style.display="none";
document.getElementById("my_timer").style.display="none";
document.getElementById("final").style.display="block";
return;
}
h--;
m = 60;
if (h < 10) h = "0" + h;
}
m--;
if (m < 10) m = "0" + m;
s = 59;
}
else s--;
if (s < 10) s = "0" + s;
document.getElementById("my_timer").innerHTML = h+":"+m+":"+s;
setTimeout(startTimer, 1000);
}
document.getElementById('startgame').onclick = function(){
startTimer();
document.getElementById('game').style.display = 'block';
document.getElementById('my_timer').style.display = 'block';
document.getElementById('startgame').style.display = 'none';
}
}
</script>
<?
echo '<div class="body" style="height:17px;">'.($user['record'] > 0 ? 'Рекорд: <img src="/style/icons/hand.png" /> <b>'.$user['record'].'</b> <img src="/style/icons/'.$user['record_device'].'.png" align="middle" />' : '').'<span style="float:right;"><a class="pnav" href="/ngame.php">Новая игра</a><a class="pnav" href="/">Домой</a></span></div>
<div class="body"><center>
<span id="my_timer" style="color: #f00; font-size: 150%; font-weight: bold;">00:00:01</span>
<span id="final">Время вышло! Твой результат:</br><span id="clickme" style="font-weight: bold;font-size: 250%;">0</span></span>
</center>
<div id="game">
<center>
<img id="inp" src="/style/click.png" style="margin: 10px;"/></br>
Щелчки: <span id="count" style="font-weight: bold;">0</span>
</center>
</div>
<a href="#" id="startgame"><center><img src="/style/start.png" style="margin: 10px;"/></center></a></div>';
?><script type="text/javascript">
$('#inp')
.data('counter', 0)
.click(function() {
var counter = $(this).data('counter');
$(this).data('counter', counter + 1);
document.getElementById('clickme').innerHTML = $(this).data('counter');
document.getElementById('count').innerHTML = $(this).data('counter');
$.post("sgame.php", {
clicks: $(this).data('counter')
});
});
</script>