-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
1221 lines (1215 loc) · 46.7 KB
/
index.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="./favicon.ico">
<style>
html {
min-height: 100%;
}
body {
font-family: sans-serif;
max-width: 760px;
margin-left: auto;
margin-right: auto;
padding: 4px;
background-color: #fffff3;
}
section,hr {
max-width:720px;
margin-left: auto;
margin-right: auto;
}
li {
margin-bottom: 0.2em
}
textarea#saveArea {
width:96%;
margin-right:auto
margin-left:auto;
max-width:720px;
}
button {
@supports (width: 1cap) {
vertical-align: calc(1em - 1cap);
}
@supports not (width: 1cap) {
vertical-align: .33em;
}
}
</style>
<title>HTML-Spinner Examples</title>
</head>
<body>
<h1 style="text-align:center">
<x-spinner color="red" wt="3"></x-spinner> Spun-out with Spinner Images?
<x-spinner color="red" wt="3" dir="ccw"></x-spinner>
</h1>
<h2 style="text-align:center">
<x-fast-revspinner color="green" wt="3"></x-fast-revspinner> Try the HTML Spinner Element
<x-fast-revspinner color="green" wt="3" direction="cw"></x-fast-revspinner>
</h2>
<hr>
<section>
<div style="
width: 90%;
text-align: center;
margin-left: auto;
margin-right: auto;
display: grid;
grid-template-columns: repeat(12, 1fr);
justify-content: center;
gap: 1px;
font-size: 3em;
">
<x-spinner rotor="100" color="green" wt="1" tclr="rgba(0,55,255,.25)"></x-spinner>
<x-spinner rotor="100" wt="4" sp="0.33" tclr="rgba(0,55,255,.25)"></x-spinner>
<x-spinner rotor="101" color="blue" wt="10" tclr="rgba(0,55,255,.25)"></x-spinner>
<x-spinner rotor="101" wt="1" tclr="rgba(0,55,255,.25)" rstyle="dotted"></x-spinner>
<x-spinner rotor="101" wt="4" tclr="rgba(0,55,255,.25)" rstyle="dotted"></x-spinner>
<x-spinner rotor="1111" color="red" wt="3" dir="ccw" rstyle="dotted"></x-spinner>
<x-spinner rotor="1111" color="#0f0" wt="8" tclr="rgba(0,55,255,.25)" rstyle="dotted"></x-spinner>
<x-spinner rotor="11" wt="2" tclr="rgba(0,55,255,.25)" rstyle="double"></x-spinner>
<x-spinner rotor="11" color="purple" wt="4" tclr="rgba(0,55,255,.25)" rstyle="double"></x-spinner>
<x-spinner rotor="11" wt="10" tclr="rgba(0,55,255,.25)"></x-spinner>
<x-spinner rotor="111" color="pink" wt="3" tclr="rgba(0,55,255,.25)"></x-spinner>
<x-spinner rotor="111" color="blue" wt="10" tclr="rgba(0,55,255,.25)"></x-spinner>
</div>
<div style="
width: 90%;
text-align: center;
margin-left: auto;
margin-right: auto;
">
<code style="white-space: pre-wrap;">
Here's the markup for one of the above. Can you see which one?
<x-spinner rotor="1111" color="red" wt="3" dir="ccw" rstyle="dotted"></x-spinner>
</code>
</div>
</section>
<hr>
<section style="padding-left:2.4em;">
<style>
.spin1 {
list-style: none;
padding: 0;
}
.spin1 li {
display: flex;
align-items: center;
margin-bottom: 0.5em;
}
.spin1 li x-spinner {
margin-right: 0.5em;
}
</style>
<ul class="spin1" style="font-size:1.6em;">
<li> Customizable</li>
<li> No Dependencies or Frameworks</li>
<li> Compatible with standard HTML, css, and Javascript</li>
<li> Works in all modern browsers</li>
<li> May be entirely controlled in markup, or by script, or in combination</li>
<li> A custom spinner can be easily saved as plain HTML and CSS </li>
</ul>
</section>
<hr>
<section style="max-width: 720px;margin-left:auto;margin-right:auto;">
<p>
<b>Quick Start:</b><br>
<ol style="font-size:1.2em;">
<li>Get the script <code> spinnerComponent.js </code> (see <a href="#sources">Sources</a>, below)
<li>Place it where your scripts are, e.g., in a <code>./scripts</code> directory</li>
<li>In your HTML, load the script:
<code style="white-space: pre-wrap;">
<script src="./scripts/spinnerComponent.js"></script></code></li>
<li>Place a spinner where you want it</li>
<li><x-spinner></x-spinner> Default: <code> <x-spinner></x-spinner> </code></li>
<li><x-spinner rotor="1111" rstyle="dotted" sp=".5" color="green"></x-spinner> Fast Dotted Green:<br><code> <x-spinner rstyle="dotted" sp=".5" color="green"></x-spinner> </code></li>
</ol>
</p>
<p>
See <a href="#rstyles">Rotor Styles</a>, below, for an organized view of variations.<br>
See the README file in the <a href="#sources">Sources</a> download for extensive instructions and documentation.
</p>
</section>
<hr>
<section style="max-width:600px;margin-left:auto;margin-right:auto;">
<h2 style="text-align:center">Motivation</h2>
<p>
I'm fed up with the limitations of using animated images for "wait spinners".
Now I've made a customizable spinner, the SpinnerElement,
that works without images in any HTML layout.
</p>
<p>
Good web interface design shows what's happening.
A long background process calls for some kind of indicator,
especially if no other action is possible on the page until
that process completes (or bails out). The most common indicators are
<dfn>progress bars</dfn> and <dfn>wait spinners</dfn>. Here I'm focused on
a better option for wait spinners<x-spinner></x-spinner>.
</p>
<p>
I need ways let my clients know their data-oriented sites are busy, not dead.
For convenience, I've settled for a few generic animated GIFs that I bet you've seen.
The alternative is designing a new one, or searching through millions of spinner images online.
But that's not the whole task...
</p>
<p>
What if the client has a color scheme the spinner should fit into?
Or a typeface whose light weight makes the generic spinner look too bulky?
Sizing someone's nice downloaded spinner image to fit its spot in the layout also takes time and attention, especially if it's in a line of text.
</p>
</section>
<hr>
<section style="max-width: 720px;margin-left:auto;margin-right:auto;">
<p>
<b>Introducing the HTML SpinnerElement</b><br>
The SpinnerElement is constructed automatically within your HTML when your page loads the Javascript
<code>spinnerComponent.js</code>.
</p>
<p>
Yes, Javascript. Why is loading a Javascript-based spinner better than
including an image file?
<ul>
<li>Versatility via familiar HTML tag attribute assignments;
<li>Programmability - if you want it;</li>
<li>Works like a text character in HTML layouts;</li>
<li style="color:red;font-size:1.4em;">Takes the size and color <x-spinner></x-spinner> of its surroundings - unless you specify otherwise;</li>
<li>Include text or another HTML element as prefix and/or suffix;</li>
<li>No visual degradation at any scale;</li>
<li>Can be tuned to specifications in your style book or branding guide;</li>
<li>Focus on what you want, not where to download it or how to make it.</li>
</ul>
</p>
<p>
Spinners do not rely on Javascript to run. When <code>spinnerComponent.js</code> loads,
it executes once to construct the SpinnerElement class and attach it
to the HTML document. When a spinner is rendered in markup, its internal css provides its format and rotation.
<code>spinnerComponent.js</code> also provides an optional programming interface whose methods momentarily execute only when adding or modifying spinners.
</p>
<section style="max-width:600px;margin-left:auto;margin-right:auto;">
<h4 style="text-align:center">Side Topic: Static Spinners</h4>
<p>
Once created, a specific spinner may be saved as plain HTML and CSS, needing no further Javascript.
If that is the only spinner for the page/site, loading spinnerComponent.js is not necessary.
The saved spinner is a small HTML fragment composed of 'div' and 'span' elements,
along with a 'style' element with properties that control the spinner's appearance and rotation.
</p>
<p>
Any spinner may be saved, either by stringifying it from a script,
or by extracting it from the rendered html of the page it's created on.
Some of the examples below put the stringified spinner in the web browser's console, where they can be copied.
One example, the button "Add and View" adds a spinner and shows its stringified source.
</p>
<p>
The source of a dynamic spinner is normally hidden in the shadow DOM,
and instances of the spinner may be varied in the same document by varying the attributes of the
x-spinner element wherever it's placed.
A saved spinner uses the inner HTML and CSS directly in the main DOM, removing the need for any Javascript,
but also introducing potential HTML and CSS naming collisions, requiring any variations
to be done directly in the spinner-related CSS, and, of course, removing its Javascript methods.
</p>
<p>
A saved spinner will still inherit the size and color of the text and markup it's placed in.
</p>
</section>
<p>
Spinners follow ARIA accessibility guidelines. The rotors themselves are invisible to screen readers, because they have no content to read. Any included prefixes and suffixes will be seen and read. The spinner may also be marked as a "live" area by assigning it the attribute <code>aria-wrap="true"</code>; it will then assume the role of communicating changes in status, such as when a long-running process completes.
</p>
<p>
The SpinnerElement is self-contained. Spinners have no side-effects on the rest of the layout, and multiple
spinners in the same layout have no effect on each other. Being encapsulated also keeps the SpinnerElement
compatible with other web app resources, scripts, modules, and frameworks.
Creation of the SpinnerElement utilizes HTML, css, and Javascript capabilities
that are standardized and broadly adopted by web browsers.
</p>
<p>
Loading cost and time for <code>spinnerComponent.js</code> is minimal,
with a file size less than 20k.
</p>
</section>
<hr>
<section style="margin-left:auto;margin-right:auto;">
<h2 style="text-align:center">Some Examples</h2>
<p style="background-color:yellow;padding:2em;margin-left:0;font-size:2em;">
<x-spinner prefix="We'll be right back ... " rotor="1" trace-color="transparent" back-color="white" color="red"></x-spinner>
</p>
<code style="white-space: pre-wrap;">
<p style="background-color:yellow;padding:2em;margin-left:0;font-size:2em;">
<x-spinner prefix="We'll be right back ... " rotor="1" trace-color="transparent" back-color="white" color="red"></x-spinner>
</p>
</code>
<hr>
<p style="color:blue; font-size:2em;">
<x-spinner prefix="Is it moving?" kerning="1ch" rotor="101" wt=".195" bgclr="gold" tclr="red" bkclr="rgba(0,55,255,.25)"></x-spinner>
</p>
<code style="white-space: pre-wrap;">
<p style="color:blue; font-size:2em;">
<x-spinner prefix="Is it moving?" kerning="1ch" rotor="101" wt=".195" bgclr="gold" tclr="red" bkclr="rgba(0,55,255,.25)"></x-spinner>
</p>
</code>
<hr>
<p style="font-size:2em;">
<x-spinner onclick="this.stopGo()" rotor="101" wt=".495" sp="2" tclr="rgba(255,255,0,1)" kern="1ch" suffix="Restricted"></x-spinner>
</p>
<code style="white-space: pre-wrap;">
<p style="font-size:2em;">
<x-spinner onclick="this.stopGo()" rotor="101" wt=".495" sp="2" tclr="rgba(255,255,0,1)" kern="1ch" suffix="Restricted"></x-spinner>
</p>
</code>
<hr>
<p style="font-size:2em;">
<x-spinner onclick="this.stopGo()" rotor="101" rstyle="dotted" wt="3" sp="1" tclr="rgba(255,51,0,1)" kern="1ch" suffix="Click to Start/Stop"></x-spinner>
</p>
<code style="white-space: pre-wrap;">
<p style="font-size:2em;">
<x-spinner onclick="this.stopGo()" rotor="101" rstyle="dotted" wt="3" sp="1" tclr="rgba(255,51,0,1)" kern="1ch" suffix="Click to Start/Stop"></x-spinner>
</p>
</code>
<hr>
<p style="font-size:2.4em;color:#ff0000;">
<x-spinner color="#ff0000" rotor="101" wt="8" speed="1" direction="cw" back-color=transparent ></x-spinner>
Recording in Progress
<x-spinner color="#ff0000" rotor="0101" wt="8" speed="1" direction="cw" back-color=transparent "></x-spinner>
</p>
<code style="white-space: pre-wrap;">
<p style="font-size:2.4em;color:#ff0000;">
<x-spinner color="#ff0000" rotor="101" wt="8" speed="1" direction="cw" back-color=transparent ></x-spinner>
Recording in Progress
<x-spinner color="#ff0000" rotor="0101" wt="8" speed="1" direction="cw" back-color=transparent "></x-spinner>
</p>
</code>
<hr>
<div style="color:rgba(92, 51, 23, 1); font-size:2em;">
<x-spinner prefix="Research " suffix=" takes time." kern="0ch" wt=".195" speed=".75" rotor="1110" direction="cw" back-color="rgba(92, 51, 23, 0.2)" trace-color="transparent"></x-spinner>
</div>
<code style="white-space: pre-wrap;">
<div style="color:rgba(92, 51, 23, 1); font-size:2em;">
<x-spinner prefix="Research " suffix=" takes time." kern="0ch" wt=".195" speed=".75" rotor="1110" direction="cw" back-color="rgba(92, 51, 23, 0.2)" trace-color="transparent"></x-spinner>
</div>
</code>
<hr>
<button type="button" onclick="
const spin6 = document.getElementById('sp6');
if (this.innerHTML === 'Chase') {
// set attributes individually with JS built-in .setAttribute
spin6.setAttribute('rotor-color', '#00dd00');
spin6.setAttribute('direction', 'cw');
spin6.setAttribute('sp', '.4');
spin6.setAttribute('wt', '3');
spin6.setAttribute('rstyle', 'dotted');
spin6.setAttribute('suf', ' Chasing!');
spin6.style.fontStyle = 'italic';
spin6.style.color = '#00dd00';
this.innerHTML = 'Scan';
} else {
// set attributes in one op with spinner's .setAttributes method
spin6.setAttributes({
color: '#ddd',
direction: 'ccw',
sp: '1.5',
wt: '8',
suf: ' Scanning...',
rstyle: 'solid',
rstatus: 'running',
rotor: '1'
});
spin6.style.fontStyle = 'normal';
spin6.style.color = '#ccc';
this.innerHTML = 'Chase';
}
// Show the rendered spinner in the console:
console.log( spin6.toString() );
">Scan</button>
<p style="font-size:4em;margin-top:0;margin-bottom:0;">
<!-- These attributes define the spinner when first loaded -->
<x-spinner id="sp6" rstatus="paused" rotor="1" color="#ddd" sp="1.5" tclr="#ccf" wt="8" dir="ccw" kern="0em" role="status" aria-wrap='true'></x-spinner><br>
</p>
<code style="white-space: pre-wrap;">
<button type="button" onclick="
const spin6 = document.getElementById('sp6');
if (this.innerHTML === 'Chase') {
// set attributes individually with JS built-in .setAttribute
spin6.setAttribute('rotor-color', '#00dd00');
spin6.setAttribute('direction', 'cw');
spin6.setAttribute('sp', '.4');
spin6.setAttribute('wt', '3');
spin6.setAttribute('rstyle', 'dotted');
spin6.setAttribute('suf', ' Chasing!');
spin6.style.fontStyle = 'italic';
spin6.style.color = '#00dd00';
this.innerHTML = 'Scan';
} else {
// set attributes in one op with spinner's .setAttributes method
spin6.setAttributes({
color: '#ddd',
direction: 'ccw',
sp: '1.5',
wt: '8',
suf: ' Scanning...',
rstyle: 'solid',
rstatus: 'running',
rotor: '1'
});
spin6.style.fontStyle = 'normal';
spin6.style.color = '#ccc';
this.innerHTML = 'Chase';
}
// Show the rendered spinner in the console:
console.log( spin6.toString() );
">Scan</button>
<p style="font-size:4em;margin-top:0;margin-bottom:0;">
<!-- These attributes define the spinner when first loaded -->
<x-spinner id="sp6" rstatus="paused" rotor="1" color="#ddd" sp="1.5" tclr="#ccf" wt="8" dir="ccw" kern="0em" role="status" aria-wrap='true'></x-spinner><br>
</p>
</code>
<hr>
<button type="button" onclick="
// Yes, start a spinner element from raw text
if (this.innerHTML == 'Search') {
let spn = `<x-spinner id='spinMe'></x-spinner>`;
document.getElementById('searching').innerHTML = spn;
const spinM = document.getElementById('spinMe');
spinM.setAttribute('sp', '.5');
spinM.setAttribute('rotor-style', 'double');
spinM.setAttribute('pre', 'Searching ... ');
spinM.setAttribute('direction', 'cw');
spinM.setAttribute('trace-color', 'transparent' );
console.log( spinM.toString() );
this.innerHTML = 'Cancel';
}
else {
document.getElementById('searching').innerHTML = ' ';
this.innerHTML = 'Search';
}
">Search</button>
<h2 id="searching" style="color:red;"> </h2>
<code style="white-space: pre-wrap;">
<button type="button" onclick="
// Yes, start a spinner element from raw text
// Note need to use '&lt;' instead of '<'
if (this.innerHTML == 'Search') {
let spn = `&lt;x-spinner id='spinMe'>&lt;/x-spinner>`;
document.getElementById('searching').innerHTML = spn;
const spinM = document.getElementById('spinMe');
spinM.setAttribute('sp', '.5');
spinM.setAttribute('rotor-style', 'double');
spinM.setAttribute('pre', 'Searching ... ');
spinM.setAttribute('direction', 'cw');
spinM.setAttribute('trace-color', 'transparent' );
console.log( spinM.toString() );
this.innerHTML = 'Cancel';
}
else {
document.getElementById('searching').innerHTML = ' ';
this.innerHTML = 'Search';
}
">Search</button>
<h2 id="searching" style="color:red;"> </h2>
</code>
<hr>
<p style="font-size:3em;margin-top:0;margin-bottom:0;">
<button type="button" style="width:6em;" onclick="
const pausebtn = document.getElementById('pauseBtn');
pausebtn.style.visibility = 'visible';
const spng = document.getElementById('spinning');
if (this.innerHTML=='Spin It') {
const sp = new SpinnerElement( {} );
sp.id = 'thisSpinner';
spng.innerHTML = '';
spng.appendChild(sp);
sp.setAttributes({color: 'turquoise', suffix: ' Spinning', rstyle: 'double', role: 'status', 'aria-wrap': 'true' });
this.innerHTML='Stop It';
}
else {
spng.innerHTML = ' ';
pausebtn.style.visibility = 'hidden';
this.innerHTML='Spin It';
}
">Spin It</button> <button type="button" id="pauseBtn" style="visibility:hidden;width:6em;" onclick="
const sp = document.getElementById('thisSpinner');
if (!sp) {return};
if (this.innerHTML == 'Pause') {
sp.setSuffix(' Paused')
sp.pause();
this.innerHTML = 'Resume';
}
else {
sp.setSuffix(' Spinning ');
sp.go();
this.innerHTML = 'Pause';
}">Pause</button>
<span id="spinning"> </span>
</p>
<code style="white-space: pre-wrap;">
<p style="font-size:3em;margin-top:0;margin-bottom:0;">
<button type="button" style="width:6em;" onclick="
const pausebtn = document.getElementById('pauseBtn');
pausebtn.style.visibility = 'visible';
const spng = document.getElementById('spinning');
if (this.innerHTML=='Spin It') {
const sp = new SpinnerElement( {} );
sp.id = 'thisSpinner';
spng.innerHTML = '';
spng.appendChild(sp);
sp.setAttributes({color: 'turquoise', suffix: ' Spinning', rstyle: 'double', role: 'status', 'aria-wrap': 'true' });
this.innerHTML='Stop It';
}
else {
spng.innerHTML = ' ';
pausebtn.style.visibility = 'hidden';
this.innerHTML='Spin It';
}
">Spin It</button> <button type="button" id="pauseBtn" style="visibility:hidden;width:6em;" onclick="
const sp = document.getElementById('thisSpinner');
if (!sp) {return};
if (this.innerHTML == 'Pause') {
sp.setSuffix(' Paused')
sp.pause();
this.innerHTML = 'Resume';
}
else {
sp.setSuffix(' Spinning ');
sp.go();
this.innerHTML = 'Pause';
}">Pause</button>
<span id="spinning"> </span>
</p>
</code>
<hr>
<p id="pace" style="font-size:2em;">
<button type="button" onclick="
if (this.innerHTML=='Pace Me') {
this.currentSpeedIdx = 0;
this.innerHTML = 'Step';
}
const speeds = [ '0.1', '0.25', '0.5', '0.75', '1', '1.5', '2', '4', 'Reset' ];
if (getSpinner('#sp2')) { removeSpinner('#sp2') }
const sp2 = new SpinnerElement({id: 'sp2'});
appendSpinner(sp2, '#pace');
let curSpd = speeds[this.currentSpeedIdx];
if (curSpd === 'Reset') {
this.innerHTML = 'Pace Me';
removeSpinner('#sp2');
this.currentSpeedIdx = 0;
}
else {
let ss = curSpd === '1' ? '' : 's';
sp2.setAttributes({'color': 'blue', 'speed': curSpd, kern: '1ch', 'prefix': 'Rotation in', 'suffix': curSpd + ' second' + ss});
this.currentSpeedIdx += 1;
}
">Pace Me</button>
</p>
<code style="white-space: pre-wrap;">
<p id="pace" style="font-size:2em;">
<button type="button" onclick="
if (this.innerHTML=='Pace Me') {
this.currentSpeedIdx = 0;
this.innerHTML = 'Step';
}
const speeds = [ '0.1', '0.25', '0.5', '0.75', '1', '1.5', '2', '4', 'Reset' ];
if (getSpinner('#sp2')) { removeSpinner('#sp2') }
const sp2 = new SpinnerElement({id: 'sp2'});
appendSpinner(sp2, '#pace');
let curSpd = speeds[this.currentSpeedIdx];
if (curSpd === 'Reset') {
this.innerHTML = 'Pace Me';
removeSpinner('#sp2');
this.currentSpeedIdx = 0;
}
else {
let ss = curSpd === '1' ? '' : 's';
sp2.setAttributes({'color': 'blue', 'speed': curSpd, kern: '1ch', 'prefix': 'Rotation in', 'suffix': curSpd + ' second' + ss});
this.currentSpeedIdx += 1;
}
">Pace Me</button>
</p>
</code>
<hr>
<button type="button" role='alert' style="font-weight:bold;height:1.6em;width:12ch;font-size:1.4em" onclick="
if (this.innerHTML=='Run') {
const sp = new SpinnerElement;
sp.id = 'thatSpinner';
this.innerHTML = '';
this.appendChild(sp);
sp.setAttributes({'color': 'purple', 'prefix': 'Cancel '});
}
else {
this.innerHTML='Run';
}
">Run</button>
<code style="white-space: pre-wrap;">
<button type="button" role='alert' style="font-weight:bold;height:1.6em;width:12ch;font-size:1.4em" onclick="
if (this.innerHTML=='Run') {
const sp = new SpinnerElement;
sp.id = 'thatSpinner';
this.innerHTML = '';
this.appendChild(sp);
sp.setAttributes({'color': 'purple', 'prefix': 'Cancel '});
}
else {
this.innerHTML='Run';
}
">Run</button>
</code>
<hr>
<div style="font-size:2em;">
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;font-size:.8rem;">
Click to View
</div>
<div id="here0" style="display:inline-block;width:3em;text-align:center;font-size:.8rem;">Example</div>
<div style="font-size:.8rem;display:inline-block;">
Layout: External Functions and Spinner Methods:
</div>
</div>
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;">
<button type="button" onclick="
if (this.innerHTML === 'Insert It') {
const sp1=new SpinnerElement({id: 'sp1_id'});
insertSpinner(sp1,'#here1');
this.innerHTML='Remove It';
}
else {
removeSpinner('#sp1_id');
document.querySelector('#here1').innerHTML = ' ';
this.innerHTML='Insert It';
}
">Insert It</button>
</div>
<div id="here1" style="display:inline-block;width:3em;text-align:center;"></div>
<div>
<code style="white-space: pre-wrap;font-size:.8rem;display:inline-block;">
insertSpinner(sp1,'#here1');
removeSpinner( [ sp1 | '#sp1_id' ] );
</code>
</div>
</div>
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;">
<button type="button" onclick="
if (this.innerHTML === 'Append It') {
const sp2=new SpinnerElement({id: 'sp2_id',
rotor:'1111', rstyle:'dotted',wt:'5'});
appendSpinner(sp2,'#here2');
this.innerHTML='Remove It';
}
else {
removeSpinner('#sp2_id');
this.innerHTML='Append It';
}
">Append It</button>
</div>
<div id="here2" style="display:inline-block;width:3em;text-align:center;"> Hi </div>
<div>
<code style="white-space: pre-wrap;font-size:.8rem;display:inline-block;">
appendSpinner(sp2,'#here2');
removeSpinner( [ sp2 | '#sp2_id' ] );
</code>
</div>
</div>
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;">
<button type="button" onclick="
const sp3 = document.getElementById('sp3_id');
if (this.innerHTML === 'Show It') {
sp3.show();
this.innerHTML='Hide It';
}
else {
sp3.hide();
this.innerHTML='Show It';
}
">Show It</button>
</div>
<div id="here3" style="display:inline-block;width:3em;text-align:center;"> |<x-spinner id="sp3_id" style="display:none;"></x-spinner>| </div>
<div>
<code style="white-space: pre-wrap;font-size:.8rem;display:inline-block;">
sp3.show(); sp3.hide();
</code>
</div>
</div>
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;">
<button type="button" onclick="
const sp4 = document.getElementById('sp4_id');
if (this.innerHTML === 'Unveil It') {
sp4.unveil();
this.innerHTML='Veil It';
}
else {
sp4.veil();
this.innerHTML='Unveil It';
}
">Unveil It</button>
</div>
<div id="here4" style="display:inline-block;width:3em;text-align:center;"> |<x-spinner id="sp4_id" style="visibility:hidden;"></x-spinner>| </div>
<div>
<code style="white-space: pre-wrap;font-size:.8rem;display:inline-block;">
sp4.unveil(); sp4.veil();
</code>
</div>
</div>
<div style="display:grid;grid-template-columns: 4em 4em 1fr;">
<div style="display:inline-block;">
<button type="button" onclick="
let sp5 = document.getElementById('sp5_id');
if (this.innerHTML === 'Stop It') {
sp5.stop();
this.innerHTML='Start It';
}
else {
sp5.run();
this.innerHTML='Stop It';
}
">Start It</button>
</div>
<div id="here5" style="display:inline-block;width:3em;text-align:center;"> <x-spinner id="sp5_id" rstatus="paused"></x-spinner> </div>
<div>
<code style="white-space: pre-wrap;font-size:.8rem;display:inline-block;">
sp5.run(); sp5.stop();
</code>
</div>
</div>
</div>
</section>
<hr id="save">
<section>
<button onclick="
const tgt = document.getElementById('saveSp');
const saveTgt = document.getElementById('saveArea');
if (this.innerHTML=='Add and View') {
const saveSpinner = new SpinnerElement({
id: 'sp_save',
rotor:'1111',
rstyle:'dotted',
wt:'5',
color:'magenta',
kerning: '1ch',
suffix: 'Now Spinning...'
});
appendSpinner(saveSpinner,tgt);
const spStr = saveSpinner.toString();
saveTgt.style.height = '48em';
saveTgt.innerHTML = spStr;
this.innerHTML = 'Hide';
}
else {
removeSpinner('#sp_save');
saveTgt.innerHTML = '';
saveTgt.style.height = '2em';
this.innerHTML = 'Add and View';
}
">Add and View</button>
<div id="saveSp"></div>
<textarea id="saveArea"></textarea>
</section>
<hr id="rstyles">
<section>
<style>
.demoSpnr {
font-size: 2em;
@media screen and (min-width: 660px) {
font-size: 3em;
}
}
.demoHdr {
font-size: .6em;
@media screen and (min-width: 660px) {
font-size: .8em;
}
}
</style>
<h2 style="text-align:center;">
<x-spinner rstyle="dotted" rotor="1010" class="demoSpnr" color="magenta" style="font-size:inherit;"></x-spinner> Rotor Styles
<x-spinner rstyle="dotted" rotor="1010" class="demoSpnr" color="magenta" style="font-size:inherit;"></x-spinner>
</h2>
<div style="text-align:center;">
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('solid')
});
">Solid</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('double')
});
">Double</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('dotted')
});
">Dotted</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('dashed')
});
">Dashed</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('ridge')
});
">Ridge</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('groove')
});
">Groove</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('inset')
});
">Inset</button>
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('outset')
});
">Outset</button> |
<button onclick="
if (this.innerHTML === 'Stop Everything!') {
const targetSpinners = getSpinners('.demoSpnr');
targetSpinners.forEach(spinner => { spinner.pause() });
this.innerHTML = 'OK. Carry On.'
}
else {
const targetSpinners = getSpinners('.demoSpnr');
targetSpinners.forEach(spinner => { spinner.run() });
this.innerHTML = 'Stop Everything!';
}
">Stop Everything!</button>
</div>
<hr>
<div style="font-family:sans-serif;color:green;">
<div style="margin: 0 auto;width:100%;text-align:center;">
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div class="demoHdr" style="font-size:.8em;">weight→<br>rotor↓</div>
<div class="demoHdr">Default<br>.195</div>
<div class="demoHdr">1<br>.045</div>
<div class="demoHdr">2<br>.095</div>
<div class="demoHdr">3<br>.145</div>
<div class="demoHdr">4<br>.195</div>
<div class="demoHdr">5<br>.245</div>
<div class="demoHdr">6<br>.295</div>
<div class="demoHdr">7<br>.345</div>
<div class="demoHdr">8<br>.395</div>
<div class="demoHdr">9<br>.445</div>
<div class="demoHdr">10<br>.495</div>
</div>
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div><br>1000</div>
<div><X-SPINNER class="demoSpnr" rtr="1" wt=".195" tclr="rgba(0,55,255,.25)"></X-SPINNER></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".045" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".095" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".145" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".245" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".295" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".345" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".395" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1" wt=".445" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-fast-revspinner class="demoSpnr" rtr="1" wt=".495" tclr="rgba(0,55,255,.25)"></x-fast-revspinner></div>
</div>
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div><br>1010</div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".045" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".095" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".145" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".245" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".295" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".345" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".395" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="101" wt=".445" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-fast-revspinner class="demoSpnr" rtr="101" wt=".495" tclr="rgba(0,55,255,.25)"></x-fast-revspinner></div>
</div>
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div><br>1100</div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".045" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".095" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".145" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-fast-revspinner class="demoSpnr" rtr="11" wt=".245" tclr="rgba(0,55,255,.25)"></x-fast-revspinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".295" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".345" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".395" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".445" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="11" wt=".495" tclr="rgba(0,55,255,.25)"></x-spinner></div>
</div>
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div><br>1110</div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".045" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".095" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".145" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".245" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".295" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".345" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".395" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".445" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="111" wt=".495" tclr="rgba(0,55,255,.25)"></x-spinner></div>
</div>
<div style="display:grid;grid-template-columns: repeat(12, 1fr);gap:1px;justify-content:center;">
<div><br>1111</div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".045" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".095" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-fast-revspinner class="demoSpnr" rtr="1111" wt=".145" tclr="rgba(0,55,255,.25)"></x-fast-revspinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".245" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".295" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".345" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".395" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".445" tclr="rgba(0,55,255,.25)"></x-spinner></div>
<div><x-spinner class="demoSpnr" rtr="1111" wt=".495" tclr="rgba(0,55,255,.25)"></x-spinner></div>
</div>
</div>
</div>
<p>
All of the spinners above use the same basic spinner, with font-size flexing from 2em to 3em set in the page's style sheet,
with the rotor color green inherited from the containing <code> <div></code>, and the spinner's own markup specifying the light blue trace color.
The table shows how the spinner varies with different rotor types and weights,
and the buttons above change the rotor style for the whole set of spinners, which are identified in the HTML markup by the class "demoSpnr".
</p>
<p>
Here is the spinner markup for one of the spinners above:
<code style="white-space: pre-wrap;">
<div style="color:green;">
<x-spinner class="demoSpnr" rtr="101" wt=".195" tclr="rgba(0,55,255,.25)"></x-spinner>
</div>
</code>
yielding: <x-spinner rtr="101" wt=".195" class="demoSpnr" tclr="rgba(0,55,255,.25)" rclr="green" style="font-size:3em;"></x-spinner>,
which still has the class "demoSpnr" so it has the size of the spinners above,
and it will change rotor style when you click the buttons above.
</p>
<p>
Here is one of the buttons that sets the style of the rotors assigned the "demoSpnr" class,
using one of the spinner's built-in methods:
<code style="white-space: pre-wrap;">
<button type="button" onclick="
const targetSpinners = document.querySelectorAll('.demoSpnr');
targetSpinners.forEach(spinner => {
spinner.setRotor('dotted');
});
">Dotted</button>
</code>
</p>
</section>
<hr>
<section>
<style>
.sqr2crcl {
font-size: 1.2em;
@media screen and (min-width: 660px) {
font-size: 1.6em;
}
}
</style>
<h3 style="text-align:center;"> How is this spinner made?</h3>
<p>
These images illustrate how the <em>rotor</em> - the spinning part - is made from a square box HTML element with a border.
One or more of the top, right, bottom, and left, borders are colored differently from the rest.
Then the sides of the square are made round by giving the corners of the square a radius of 50% of its size.
The result is four "quadrants" of the spinner to color and format for different spinners.
</p>
<div style="
display:grid;
grid-template-columns: repeat(5, 1fr);
gap:1px;
justify-content:center;
text-align:center">
<div>
<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
"></span>→<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border-radius: 50%;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
"></span>
</div>
<div>
<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
border-bottom: .195cap solid rgba(0,80,80,.75);
"></span>→<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border-radius: 50%;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
border-bottom: .195cap solid rgba(0,80,80,.75);
"></span>
</div>
<div>
<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
border-left: .195cap solid rgba(0,80,80,.75);
"></span>→<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border-radius: 50%;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
border-left: .195cap solid rgba(0,80,80,.75);
"></span>
</div>
<div>
<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;
border: .195cap solid rgba(0,80,80,.1);
border-top: .195cap solid rgba(0,80,80,.75);
border-bottom: .195cap solid rgba(0,80,80,.75);
border-left: .195cap solid rgba(0,80,80,.75);
"></span>→<span class="sqr2crcl" style="
display: inline-block;
width: 1cap;
height: 1cap;