-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.html
More file actions
109 lines (104 loc) · 2.74 KB
/
Copy pathtask2.html
File metadata and controls
109 lines (104 loc) · 2.74 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<title>My counter</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<div class="hiddenValue">0</div>
<div class="counterDiv1">
<div class="counterDiv2">0</div>
<div class="counterDiv2">0</div>
<div class="counterDiv2">0</div>
<div class="counterDiv2">0</div>
</div>
<script type="text/javascript">
$(function(){
var refresh = false;
function extendCounter(value){
if (value == undefined) value = 0;
var div = $('.counterDiv1');
div.width(div.width() + 34);
div.prepend("<div class='counterDiv2'>"+ value +"</div>")
};
function initCounter(value){
value = zeroFill(value);
var count = $('.counterDiv1 > div').length;
if (value.length > count) {
for (var i=0;i<value.length-count;i++){
extendCounter();
}
}
$('.hiddenValue').text(value);
$('.counterDiv2').each(function(index){
$(this).text(value[index]);
});
}
function getValue(){
return $('.hiddenValue').text()
}
function incValue(inc){
var value = parseInt(getValue());
if (inc == undefined) inc = 1
if (value >= 9999-inc) {
if ((value+inc).toString().length > value.toString().length) extendCounter()
}
setValue(value+inc);
}
function setValue(value){
value = zeroFill(value);
$('.counterDiv2').each(function(index){
$(this).text(value[index]);
});
$('.hiddenValue').text(value);
}
function zeroFill(value){
if (value < 1000){
var strValue = ("0000" + value).slice(-4); // fills with zeros
} else {
var strValue = value.toString();
}
return strValue
}
$('.counterDiv1').click(function(){
if (!refresh) {
initCounter(getValue());
refresh = setInterval(incValue, 10, 10101);
} else {
clearInterval(refresh);
refresh = false;
}
});
});
</script>
<style>
.counterDiv1 {
position: fixed;
background: #f0f0f0; /* Цвет фона */
height: 30px;
width: 152px;
right: 15px;
border: 2px solid;
padding: 8px;
border-radius: 10px;
-moz-border-radius: 10px;
-khtml-border-radius: 10px;
}
.counterDiv2 {
height: 20px;
width: 20px;
background: white;
border: 2px solid;
padding: 2px;
display: inline-block;
margin: 3px;
font-size: 20px;
font-weight: bold;
text-align:center;
}
.hiddenValue {
display: none;
}
</style>
</body>
</html>