-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressbox__old.html
252 lines (207 loc) · 8.66 KB
/
progressbox__old.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div>
<button id="firstButton">Button</button>
<div class='boxwrapper' id='myDivId'>
<div class="progress"></div>
<div class="content">
DIV
</div>
</div>
</div>
<hr />
<div>
<form>
<input type="number" id="getSeconds" />Seconds
<button id="secondButton">Button</button>
</form>
<div class='boxwrapper' id='myDivId2'>
<div class="progress"></div>
<div class="content" id="displaySeconds">
Nothing yet, enter and then submit.
</div>
</div>
<hr />
<h3>Third Button</h3>
<div>
<div class="verticalBox" id="box1">
<input type="number" id="seconds1" />Seconds
<div class='boxwrapper' id='wrapper1'>
<div class="progress work" id='progress1'></div>
<div class="display" id="display1">
1st WORK
</div>
</div>
</div>
<div class="verticalBox" id="box2">
<input type="number" id="seconds2" />Seconds
<div class='boxwrapper' id='wrapper2'>
<div class="progress treat" id='progress2'></div>
<div class="display" id="display2">
2nd TREAT
</div>
</div>
</div>
<div class="verticalBox" id="box3">
<button id="thirdButton3">START(3)</button>
<input type="number" id="seconds3" />Seconds
<div class='boxwrapper' id='wrapper3'>
<div class="progress work" id='progress3'></div>
<div class="display" id="display3">
3rd WORK
</div>
</div>
</div>
<div class="verticalBox" id="box4">
<input type="number" id="seconds4" />Seconds
<div class='boxwrapper' id='wrapper4'>
<div class="progress work" id='progress4'></div>
<div class="display" id="display4">
4th treat
</div>
</div>
</div>
<div class="verticalBox" id="box5">
<input type="number" id="seconds5" />Seconds
<div class='boxwrapper' id='wrapper5'>
<div class="progress work" id='progress5'></div>
<div class="display" id="display5">
last WORK!
</div>
</div>
</div>
</div>
<hr />
<div class="jumbotron">
<h2 id="mainMessage">Hit Start(3)</h2>
</div>
</div>
</body>
<script>
$(document).ready(function(){
console.log('ready');
$("button#firstButton").click(function(e){
e.preventDefault();
$('div#myDivId .progress').animate({ height: '100%' , width: '100%' }, 5000);
});
$("button#secondButton").click(function(e){
e.preventDefault();
// debugger;
var startTime= new Date();
var endTime=new Date();
var increment=$("#getSeconds").val();
endTime.setSeconds(endTime.getSeconds() + Number(increment));
var myThis=this;
function displayTimeUntilDone() {
var remainingSeconds;
var currentTime=new Date();
remainingSeconds=Math.round((endTime - currentTime)/1000)
// console.log("remainingSeconds", remainingSeconds)
// console.log(endTime, currentTime)
if (remainingSeconds>0) {
$('#displaySeconds').html(`<p>
T-${remainingSeconds}
</p>`)
setTimeout( ()=> {
displayTimeUntilDone.bind(myThis)()
}, 500)
}
else {
$('#displaySeconds').html(`<p>
DONE!
</p>`)
}
}
displayTimeUntilDone()
$('div#myDivId2 .progress').animate({ height: '0%' , width: '0%' }, 0)
$('div#myDivId2 .progress').animate({ height: '100%' , width: '100%' }, increment*1000);
$('#displaySeconds').html(`<p>
Started at ${startTime}
Ending at ${endTime}
</p>`)
});
$("button#thirdButton3").click(function(e){
e.preventDefault();
// debugger;
var startTime= new Date();
var endTime=new Date();
var myThis=this;
function displayTimeUntilDone(element, timeIncrementInput, callback) {
var increment=$(timeIncrementInput).val();
endTime.setTime(startTime.getTime() + Number(increment)*1000);
var remainingSeconds;
var currentTime=new Date();
remainingSeconds=Math.round((endTime - currentTime)/1000)
if (remainingSeconds>0) {
$(element).html(`<p>
T-${remainingSeconds}
</p>`);
setTimeout( () => {
displayTimeUntilDone(element,timeIncrementInput,callback)
// removed .bind(myThis)
}, 1000)
}
else {
$(element).html(`<p>
DONE!
</p>`)
callback();
}
}
// contemporaneously
displayTimeUntilDone("#display1", "#seconds1",
()=> {
startTime= new Date();
this.startTime=startTime;
displayTimeUntilDone("#display2", "#seconds2", ()=> {
startTime= new Date();
this.startTime=startTime;
displayTimeUntilDone("#display3", "#seconds3", ()=> {
startTime= new Date();
this.startTime=startTime;
displayTimeUntilDone("#display4", "#seconds4", ()=> {
startTime= new Date();
this.startTime=startTime;
displayTimeUntilDone("#display5", "#seconds5", console.log)})})})
});
function myBoxAnimate(color, progressIdCSS, displayCSS, fillTime) {
// debugger;
// $(progressIdCSS).css('height','0%').css('width', '0%').css('background', color)
$(progressIdCSS).css({height:'0%', width:'0%', background:color})
$(progressIdCSS).animate({ height: '100%' , width: '100%', background: color }, fillTime*1000);
$(displayCSS).html(`<p>
Started at ${startTime}
Ending at ${endTime}
</p>`)
}
var extraDelay=500;
var myDelays=[Number($("#seconds1").val()),Number($("#seconds2").val()),Number($("#seconds3").val()), Number($("#seconds4").val()), Number($("#seconds5").val())];
console.table(myDelays)
myBoxAnimate('red', "div#progress1", "#display1", myDelays[0])
$("#mainMessage").html('WORK WORK WORK')
setTimeout( ()=>{myBoxAnimate("blue", "div#progress2", "#display2", myDelays[1])}, 1000*myDelays[0] + extraDelay )
setTimeout( ()=>{$("#mainMessage").html('Hooray! GET A TREAT')}, 1000*myDelays[0] )
setTimeout( ()=>{myBoxAnimate("red", "div#progress3", "#display3", myDelays[2])}, 1000*(myDelays.slice(0,2).reduce((x,y)=>x+y)) + extraDelay )
setTimeout( ()=>{$("#mainMessage").html('more work work work, before ANOTHER TREAT')}, 1000*(myDelays.slice(0,2).reduce((x,y)=>x+y)) + extraDelay)
setTimeout( ()=>{myBoxAnimate("blue", "div#progress4", "#display4", myDelays[3])}, 1000*(myDelays.slice(0,3).reduce((x,y)=>x+y)) + extraDelay )
setTimeout( ()=>{$("#mainMessage").html('Hooray! GET A 2nd TREAT')}, 1000*(myDelays.slice(0,3).reduce((x,y)=>x+y))+ extraDelay )
setTimeout( ()=>{myBoxAnimate("red", "div#progress5", "#display5", myDelays[4])}, 1000*(myDelays.slice(0,4).reduce((x,y)=>x+y))+ extraDelay )
setTimeout( ()=>{$("#mainMessage").html('final push! You can do it!')}, 1000*(myDelays.slice(0,4).reduce((x,y)=>x+y)) + extraDelay)
});
})
</script>
</html>