-
Notifications
You must be signed in to change notification settings - Fork 2
/
countdown.html
171 lines (144 loc) · 7.58 KB
/
countdown.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript">
function Countdown(options) {
var timer,
instance = this,
seconds = options.seconds || 10,
updateStatus = options.onUpdateStatus || function () {},
counterEnd = options.onCounterEnd || function () {};
function decrementCounter() {
updateStatus(seconds);
if (seconds === 0) {
counterEnd();
instance.stop();
}
seconds--;
}
this.start = function () {
clearInterval(timer);
timer = 0;
seconds = options.seconds;
timer = setInterval(decrementCounter, 1000);
};
this.stop = function () {
clearInterval(timer);
};
}
$(document).ready(function () {
$("#btnVote").click(function () {
$('.current').removeClass('current').hide().next().removeClass('hidden').addClass('current').trigger('classChange');
if ($('.current').hasClass('last')) {
$('#btnVote').hide();
$('#btnValid').removeClass('hide');
}
});
$('.col-md-12').on('classChange', function () {
// do stuff
var timetogo = $('.current').attr("data-time");
console.log(timetogo);
$('.progress-bar').width('0%');
var myCounter = new Countdown({
seconds: timetogo, // number of seconds to count down
onUpdateStatus: function (sec) {
console.log(sec);
elapsed = timetogo - sec;
$('.progress-bar').width(((elapsed / timetogo) * 100) + "%");
$('.col-md-12').on('classChange', function () {
myCounter.stop();
});
}, // callback for each second
onCounterEnd: function () {
//alert('counter ended!');
} // final action
});
myCounter.stop();
myCounter.start();
});
//Init du Timer
var timetogo = $('.current').attr("data-time");
var myCounter = new Countdown({
seconds: timetogo, // number of seconds to count down
onUpdateStatus: function (sec) {
console.log(sec);
elapsed = timetogo - sec;
$('.progress-bar').width(((elapsed / timetogo) * 100) + "%");
$('.col-md-12').on('classChange', function () {
myCounter.stop();
});
}, // callback for each second
onCounterEnd: function () {
alert('counter1 ended!');
} // final action
});
myCounter.start();
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-10">
<div class="col-md-12 current" id="slide-84" data-time="10">
<img src="http://quiz.dev:8888/uploads/568c1f39abc7e.jpg" class="img-responsive"/>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-84" value="5" class="reponsequiz" data-id="56"/>
<label for="slide-84">A</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-84" value="10" class="reponsequiz" data-id="57"/>
<label for="slide-84">B</label>
</div>
</div>
<div class="col-md-12 hidden" id="slide-86" data-time="12">
<img src="http://quiz.dev:8888/uploads/568c1f39abf32.jpg" class="img-responsive"/>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-86" value="2" class="reponsequiz" data-id="58"/>
<label for="slide-86">A</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-86" value="10" class="reponsequiz" data-id="59"/>
<label for="slide-86">B</label>
</div>
</div>
<div class="col-md-12 hidden" id="slide-85" data-time="15">
<img src="http://quiz.dev:8888/uploads/568c1f39abd63.jpg" class="img-responsive"/>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-85" value="5" class="reponsequiz" data-id="60"/>
<label for="slide-85">A</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-85" value="10" class="reponsequiz" data-id="61"/>
<label for="slide-85">B</label>
</div>
</div>
<div class="col-md-12 hidden last" id="slide-87" data-time="16">
<img src="http://quiz.dev:8888/uploads/568c1f39bef46.jpg" class="img-responsive"/>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-87" value="5" class="reponsequiz" data-id="62"/>
<label for="slide-87">A</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input type="checkbox" name="slide-87" value="10" class="reponsequiz" data-id="63"/>
<label for="slide-87">B</label>
</div>
</div>
<div class="hidden alert alert-success" id="messfinal">Merci de votre participation</div>
</div>
<div class="col-md-2">
<div class="progress active progress-striped" id="progressouter">
<div class="progress-bar" id="progress"></div>
</div>
<input type="button" class="btn" value="Suivant" id="btnVote"/>
<input type="button" class="btn hide" value="Valider" id="btnValid"/>
<h2>Points</h2>
<span id="total">0</span>
</div>
</div>
</div>
</body>
</html>