-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.htm
More file actions
310 lines (229 loc) · 8.34 KB
/
index.htm
File metadata and controls
310 lines (229 loc) · 8.34 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!doctype html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
-->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script src="jquery-book.js"></script>
<link rel="stylesheet" href="jquery-book.css" />
<script>
/*
The <form> tag will be your container and referred to as a Book. The book contains
pages, each page is a <section>. Each section will contain a part of the form you
want displayed on that particular page. For the form to navigate between pages it
must include a next or previous button within that page. These buttons must include
the classes "page-next" or "page-prev" to function. Pages are designed to fit
the dimensions of the book container. Overriding the css layout will mess up
the animations. The book can be set to any size, or left alone to fill a bootstrap
column and remain responsive.
The plugin has 2 options.
'onPageChange': Callback for when a page is changed. Called just before the animation is triggered.
'speed' : The animation speed
The callback passes 4 values:
- index of the last page the form was on
- the current page index it just changed to
- total number of pages
- the current page name (or null if no name found)
Page names can be set by using the name attribute on the section tags. This can be useful if you
need to know when the user is on a specific page but don't know that page's index. If the attribute
is not set, the value will be NULL.
Dependencies:
1. jQuery
jQuery Validate is not required but is supported and will validate the form per page.
*/
$(document).ready(function(){
// Initialize the book
$book = $('#demo').book({
onPageChange: updateProgress,
speed:500}
);
// Example jumping to page out of order
$('#test').on('click', ()=>{$book.setPage(2)});
// form submission
$('#demo').submit((e)=>{
e.preventDefault();
if ($('#demo').valid()){
alert('Your data was sent.');
}
});
}); // end document ready
/* IE doesn't have a trunc function */
if (!Math.trunc) {
Math.trunc = function (v) {
return v < 0 ? Math.ceil(v) : Math.floor(v);
};
}
/* Update progress bar whenever the page changes */
function updateProgress(prevPageIndex, currentPageIndex, pageCount, pageName){
t = (currentPageIndex / (pageCount-1)) * 100;
const $pb = $('.progress-bar');
$pb.css('width', '0');
requestAnimationFrame(() => {
$pb.attr('aria-valuenow', t);
$pb.css('width', t+'%');
$('.progress-value').text(Math.trunc(t)+'%');
});
}
</script>
<style type="text/css">
body{background: linear-gradient(to right, #2c3b4e, #4a688a, #2c3b4e);}
.mybook{
background:#eee;
border:1px solid #ddd;
border-radius:6px;
height:300px;
section{
padding:8px;
}
.book-page-next{position:absolute;bottom:8px;right:8px;}
.book-page-prev{position:absolute;bottom:8px;left:8px;}
}
label.error{color:red;} <!-- jquery.validate -->
.progress span {
position:absolute;
left:0;
width:100%;
text-align:center;
z-index:2;
font-weight:bold;
}
.progress{
position:relative;
height: 25px;
background: #262626;
padding: 5px;
overflow: visible;
border-radius: 20px;
border-top: 1px solid #000;
border-bottom: 1px solid #7992a8;
margin-top: 50px;
}
.progress .progress-bar{
border-radius: 20px;
position: relative;
animation: animate-positive 2s;
transition:width 0.5s ease;
}
.progress .progress-value{
display: block;
padding: 3px 7px;
font-size: 13px;
color: #fff;
border-radius: 4px;
background: #191919;
border: 1px solid #000;
position: absolute;
top: -40px;
right: -10px;
}
.progress .progress-value:after{
content: "";
border-top: 10px solid #191919;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
position: absolute;
bottom: -6px;
left: 26%;
}
.progress-bar.active{
animation: reverse progress-bar-stripes 0.40s linear infinite, animate-positive 0s;
}
@-webkit-keyframes animate-positive{
0% { width: 0; }
}
@keyframes animate-positive{
0% { width: 0; }
}
</style>
</head>
<body>
<button id="test">Test</button> ← Click here to jump directly to the 3rd page
<div class="container-fluid" style="margin-top:50px;">
<div class="col-md-6 col-md-offset-3" style="overflow:hidden;padding:20px">
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" style="width:0%" >
<div class="progress-value">0%</div>
</div>
</div>
<form class="book mybook" id="demo">
<section name="page 1">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" class="form-control" placeholder="John" required><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" class="form-control" placeholder="Doe" required><br><br>
<button type="button" class="book-page-next btn btn-primary">Next</button>
</section>
<section>
<p>Contact information:</p>
<div class="col-md-12">
<label for="addr">Address:</label><br>
<input type="text" id="addr" name="addr" class="form-control" required><br>
</div>
<div class="col-md-4">
<label for="city">City:</label><br>
<input type="text" id="city" name="city" class="form-control" required><br>
</div>
<div class="col-md-4">
<label for="state">State:</label><br>
<select id="state" name="state" class="form-control" required>
<option>AK</option>
<option>AL</option>
<option>AR</option>
<option>AZ</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
</select>
</div>
<div class="col-md-4">
<label for="zip">Zip:</label><br>
<input type="text" id="zip" name="zip" class="form-control" required><br><br>
</div>
<button type="button" class="book-page-next btn btn-primary">Next</button>
</section>
<section name="transportation">
What is your mode of transportation?<br><br>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike" >
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br/>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a scooter</label><br/>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have rocket skates</label><br/><br>
<button type="button" class="book-page-prev btn btn-danger">Prev</button>
<button type="button" class="book-page-next btn btn-primary">Next</button>
</section>
<section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<a href="#">Terms of Service</a>
<input type="checkbox" id="ts" name="ts" value="1" required>
<label for="ts"> I agree</label><br>
<button type="button" class="book-page-prev btn btn-danger">Prev</button>
<button type="button" class="book-page-next btn btn-primary">Next</button>
</section>
<section>
<p>Final comments?</p>
<textarea class="form-control" style="height:60%"></textarea>
<button type="submit" class="book-page-next btn btn-success" id="sendForm">Complete</button>
</section>
<section style="margin:auto;text-align:center">
Your form has been submitted.
</section>
</form>
</div>
</div>
</body>
</html>