-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanimations.html
More file actions
executable file
·1479 lines (1296 loc) · 62.9 KB
/
animations.html
File metadata and controls
executable file
·1479 lines (1296 loc) · 62.9 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
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
<html>
<head>
<title>State-Animations.css – Ready-Made UI Animations for State.js</title>
<!-- State JS -->
<script src="src/state.js"></script>
<link rel="stylesheet" href="src/state-animations.css">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Space+Mono&display=swap" rel="stylesheet" media="print" onload="this.media='all'">
<!-- Mobile viewport meta tag -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Styles -->
<style>
html {
scroll-behavior: smooth;
}
body{
margin:0px;
padding:0px;
background-color:#060606;
color:#FFF;
font-family: 'Space Mono', monospace;
}
h1{
font-family: 'Bebas Neue', cursive;
color: #700c0c;
text-shadow: 2px 2px 2px #000000;
font-size:72px;
margin: 20px auto;
text-align: center;
}
h2{
font-family: 'Bebas Neue', cursive;
color: #700c0c;
text-shadow: 2px 2px 2px #000000;
font-size:48px;
margin: 30px 0 10px 0;
}
h3{
font-family: 'Bebas Neue', cursive;
color: #FFF;
font-size:32px;
margin: 25px 0 10px 0;
}
p {
line-height: 1.6;
margin: 15px 0;
}
.container{
background-color:#060606;
width:100%;
position:relative;
margin:auto;
padding: 40px 20px;
max-width: 1200px;
}
.example-section {
background: #111;
padding: 30px;
margin: 30px 0;
border-radius: 10px;
border-left: 5px solid #700c0c;
}
.demo-preview {
background: #1a1a1a;
padding: 40px;
border-radius: 10px;
margin: 20px 0;
text-align: center;
min-height: 150px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.code-example {
background-color: #000;
padding: 20px;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 14px;
overflow-x: auto;
margin: 20px 0;
border: 1px solid #333;
position: relative;
}
.code-example pre {
margin: 0;
color: #e8e8e8;
}
.copy-btn {
position: absolute;
top: 10px;
right: 10px;
background: #700c0c;
color: white;
border: none;
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
font-family: 'Space Mono', monospace;
}
.copy-btn:hover {
background: #a01010;
}
.button {
display: inline-block;
padding: 15px 30px;
background: #700c0c;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 5px;
font-family: 'Space Mono', monospace;
font-size: 14px;
}
.button:hover {
background: #a01010;
}
/* Health Bar Styles */
.health-container {
width: 100%;
max-width: 400px;
margin: 0 auto;
}
.health-bar {
width: 100%;
height: 40px;
background: #333;
border-radius: 20px;
overflow: hidden;
position: relative;
}
.health-fill {
height: 100%;
background: linear-gradient(90deg, #ff0000 0%, #ffff00 50%, #00ff00 100%);
width: var(--state-health-percent);
transition: width 0.3s ease-out;
}
.health-text {
text-align: center;
font-size: 24px;
font-family: 'Bebas Neue';
margin-top: 10px;
}
a {
color: #a01010;
}
a:hover {
color: #ff0000;
}
.back-link {
text-align: center;
margin: 40px 0;
font-size: 18px;
}
/* Menu System Styles */
#menuDemo #mainMenu,
#menuDemo #settingsMenu,
#menuDemo #creditsMenu {
display: none;
opacity: 0;
transform: translateY(-20px);
transition: all 0.3s;
}
#menuDemo.state-menuOpen #mainMenu {
display: block !important;
animation: menu-slide-in 0.3s forwards;
}
#menuDemo.state-settingsOpen #settingsMenu {
display: block !important;
animation: menu-slide-in 0.3s forwards;
}
#menuDemo.state-creditsOpen #creditsMenu {
display: block !important;
animation: menu-slide-in 0.3s forwards;
}
/* Hide main menu when in submenus */
#menuDemo.state-settingsOpen #mainMenu,
#menuDemo.state-creditsOpen #mainMenu {
display: none !important;
}
@keyframes menu-slide-in {
to {
opacity: 1;
transform: translateY(0);
}
}
/* Dialogue System Styles */
#dialogueDemo #dialogueBox,
#dialogueDemo #response1,
#dialogueDemo #response2 {
display: none;
opacity: 0;
}
#dialogueDemo.state-dialogueActive #dialogueBox {
display: block !important;
animation: dialogue-fade-in 0.3s forwards;
}
#dialogueDemo.state-choice1 #response1,
#dialogueDemo.state-choice2 #response2 {
display: block !important;
animation: dialogue-fade-in 0.3s forwards;
}
#dialogueDemo.state-choice1 #dialogueBox,
#dialogueDemo.state-choice2 #dialogueBox {
display: none !important;
}
@keyframes dialogue-fade-in {
to { opacity: 1; }
}
/* Inventory System Styles */
#inventoryDemo > div > div > div {
transition: all 0.3s;
}
#inventoryDemo.state-sword > div > div > div:nth-child(1),
#inventoryDemo.state-shield > div > div > div:nth-child(2),
#inventoryDemo.state-potion > div > div > div:nth-child(3),
#inventoryDemo.state-key > div > div > div:nth-child(4) {
background: #700c0c !important;
transform: scale(1.05);
box-shadow: 0 0 20px rgba(112, 12, 12, 0.6);
}
/* Cooldown System Styles */
#cooldownDemo > div > div > div > div {
transition: all 0.3s;
filter: grayscale(1) brightness(0.5);
}
#cooldownDemo.state-ability1Ready > div > div > div:nth-child(1),
#cooldownDemo.state-ability2Ready > div > div > div:nth-child(2),
#cooldownDemo.state-ability3Ready > div > div > div:nth-child(3) {
background: #700c0c !important;
filter: grayscale(0) brightness(1);
box-shadow: 0 0 20px rgba(112, 12, 12, 0.8);
animation: ability-ready-pulse 2s infinite;
}
@keyframes ability-ready-pulse {
0%, 100% { filter: brightness(1); }
50% { filter: brightness(1.3); }
}
/* Regeneration Animation */
#regenDemo.state-regenerating .health-bar {
animation: regen-pulse 2s infinite;
}
@keyframes regen-pulse {
0%, 100% { filter: brightness(1); }
50% { filter: brightness(1.5); }
}
/* Enemy State Machine Styles */
#enemyDemo > div > div:nth-child(1) {
transition: all 0.3s;
}
#enemyDemo.state-idle > div > div:nth-child(1) {
animation: enemy-idle 2s ease-in-out infinite;
}
#enemyDemo.state-attacking > div > div:nth-child(1) {
animation: enemy-attack 0.5s linear infinite;
}
#enemyDemo.state-stunned > div > div:nth-child(1) {
animation: stunned-dizzy 0.3s linear infinite;
}
#enemyDemo[data-enemyHealth="0"] > div > div:nth-child(1) {
animation: death 2s ease-out forwards;
}
@keyframes enemy-idle {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
@keyframes enemy-attack {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
/* Power-Up Demos - Apply animations directly */
#powerDemo.state-powered {
animation: power-glow 1s ease-in-out infinite alternate !important;
}
#powerDemo.state-invincible {
animation: invincible-shimmer 0.5s linear infinite !important;
}
#powerDemo.state-shielded {
animation: shield-pulse 1.5s ease-in-out infinite !important;
}
#powerDemo.state-stunned {
animation: stunned-dizzy 0.3s linear infinite !important;
}
/* Status Effect Demos */
#statusDemo.state-poisoned {
animation: poisoned-pulse 1s ease-in-out infinite !important;
}
#statusDemo.state-frozen {
animation: frozen-shake 2s ease-in-out infinite !important;
}
#statusDemo.state-burning {
animation: burning-flicker 0.3s linear infinite !important;
}
#statusDemo.state-healing {
animation: healing-sparkle 1s ease-out infinite !important;
}
#statusDemo.state-cursed {
animation: cursed-darken 1.5s ease-in-out infinite alternate !important;
}
#statusDemo.state-blessed {
animation: blessed-glow 2s ease-in-out infinite !important;
}
/* Level Up Demo */
#levelDemo.state-level-up {
animation: level-up-flash 1s ease-out !important;
}
/* Notification Demos */
#notificationDemo.state-success {
animation: success-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) !important;
}
#notificationDemo.state-error {
animation: error-shake 0.4s ease-out !important;
}
#notificationDemo.state-warning {
animation: warning-shake 0.5s ease-out !important;
}
</style>
</head>
<body>
<div class="container">
<h1>State-Animations.css</h1>
<p style="text-align:center; font-size:18px;">Ready-made CSS animations for interactive UIs with State.js. Perfect for dashboards, web apps, games, and more. Just copy and paste!</p>
<!-- Health Bar Example -->
<div class="example-section">
<h2>Progress Bar with Animations</h2>
<p>A complete progress indicator that automatically changes color and animations based on value. Perfect for health bars in games, download progress, storage meters, or any value-based UI.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="healthDemo"
class="health-container"
data-state
data-state-watch="health"
data-health="100"
data-health-min="0"
data-health-max="100">
<div class="health-bar">
<div class="health-fill"></div>
</div>
<div class="health-text">Health: <span data-state-display="health">100</span></div>
<div style="margin-top: 20px;">
<input type="range" data-state data-state-bind="healthDemo" data-state-attr="health" min="0" max="100" value="100" style="width: 300px;">
</div>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Health bar container -->
<div id="healthDemo"
data-state
data-state-watch="health"
data-health="100"
data-health-min="0"
data-health-max="100">
<div class="health-bar">
<div class="health-fill"></div>
</div>
<div>Health: <span data-state-display="health">100</span></div>
<!-- Slider that auto-updates the health -->
<input type="range"
data-state
data-state-bind="healthDemo"
data-state-attr="health"
min="0" max="100" value="100">
</div>
<style>
.health-bar {
width: 100%;
height: 40px;
background: #333;
border-radius: 20px;
overflow: hidden;
}
.health-fill {
height: 100%;
background: linear-gradient(90deg, #ff0000 0%, #ffff00 50%, #00ff00 100%);
width: var(--state-health-percent);
transition: width 0.3s ease-out;
}
</style></pre>
</div>
<p><strong>What happens automatically:</strong></p>
<ul>
<li>At 0 health: Death animation (fade + rotate)</li>
<li>At 10-30 health: Red pulsing warning</li>
<li>At 100 health: Green glow effect</li>
</ul>
</div>
<!-- Score Counter Example -->
<div class="example-section">
<h2>Counter with Milestone Animations</h2>
<p>Dynamic counter that celebrates milestones automatically. Great for scores, points, views, likes, download counts, or any numeric metric.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="scoreDemo"
data-state
data-state-watch="score"
data-score="0"
data-score-min="0"
data-score-max="1000">
<div style="font-size: 48px; font-family: 'Bebas Neue';">
Score: <span data-state-display="score">0</span>
</div>
<div style="margin-top: 20px;">
<input type="range" data-state data-state-bind="scoreDemo" data-state-attr="score" min="0" max="1000" step="10" value="0" style="width: 300px;">
</div>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Score container -->
<div id="scoreDemo"
data-state
data-state-watch="score"
data-score="0"
data-score-min="0"
data-score-max="1000">
<div class="score-display">
Score: <span data-state-display="score">0</span>
</div>
<!-- Slider to test different scores -->
<input type="range"
data-state
data-state-bind="scoreDemo"
data-state-attr="score"
min="0" max="1000" step="10" value="0">
</div>
<style>
.score-display {
font-size: 48px;
font-family: 'Bebas Neue', sans-serif;
}
</style></pre>
</div>
<p><strong>What happens automatically:</strong></p>
<ul>
<li>At 100, 500, 1000, 5000: Burst animation with glow</li>
<li>Scores automatically trigger visual celebrations!</li>
</ul>
</div>
<!-- Power-Up States Example -->
<div class="example-section">
<h2>Boolean State Toggles</h2>
<p>Visual effects for active/inactive states using boolean toggles. Perfect for power-ups in games, feature flags, premium status, active subscriptions, or any on/off state.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="powerDemo"
data-state-toggles="powered,invincible,shielded,stunned"
data-powered="false"
data-invincible="false"
data-shielded="false"
data-stunned="false"
style="font-size: 64px; font-family: 'Bebas Neue';">
PLAYER
</div>
<div style="margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;">
<button class="button" data-state data-state-trigger data-state-bind="powerDemo" data-state-toggle="powered">Toggle Powered</button>
<button class="button" data-state data-state-trigger data-state-bind="powerDemo" data-state-toggle="invincible">Toggle Invincible</button>
<button class="button" data-state data-state-trigger data-state-bind="powerDemo" data-state-toggle="shielded">Toggle Shielded</button>
<button class="button" data-state data-state-trigger data-state-bind="powerDemo" data-state-toggle="stunned">Toggle Stunned</button>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Player with power-up states -->
<div id="powerDemo"
data-state
data-state-toggles="powered,invincible,shielded,stunned"
data-powered="false"
data-invincible="false"
data-shielded="false"
data-stunned="false">
PLAYER
</div>
<!-- Buttons that toggle power-ups -->
<button data-state
data-state-trigger
data-state-bind="powerDemo"
data-state-toggle="powered">
Toggle Powered
</button>
<button data-state
data-state-trigger
data-state-bind="powerDemo"
data-state-toggle="invincible">
Toggle Invincible
</button></pre>
</div>
<p><strong>Available power-up classes:</strong></p>
<ul>
<li><code>.state-powered</code> - Golden glow pulse</li>
<li><code>.state-invincible</code> - Shimmer effect</li>
<li><code>.state-shielded</code> - Blue pulse shield</li>
<li><code>.state-stunned</code> - Dizzy rotation</li>
</ul>
</div>
<!-- Level Up Example -->
<div class="example-section">
<h2>Tier/Level Change Animation</h2>
<p>Celebrate tier changes, level ups, or rank promotions with a bright flash animation. Great for games, achievement systems, subscription tiers, or user rankings.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="levelDemo"
data-state-toggles="level-up"
data-level-up="false"
style="font-size: 64px; font-family: 'Bebas Neue';">
Level 5
</div>
<div style="margin-top: 20px;">
<button class="button" data-state data-state-trigger data-state-bind="levelDemo" data-state-toggle="level-up">Trigger Level Up</button>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Level display -->
<div id="levelDemo"
data-state
data-state-toggles="level-up"
data-level-up="false">
Level 5
</div>
<!-- Button to trigger animation -->
<button data-state
data-state-trigger
data-state-bind="levelDemo"
data-state-toggle="level-up">
Trigger Level Up
</button></pre>
</div>
</div>
<!-- Status Effects Example -->
<div class="example-section">
<h2>Status Indicators</h2>
<p>Visual effects for different status states. Perfect for game effects (poisoned, frozen, burning, healing), system states (processing, syncing, error), or any conditional visual feedback.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="statusDemo"
data-state-toggles="poisoned,frozen,burning,healing,cursed,blessed"
data-poisoned="false"
data-frozen="false"
data-burning="false"
data-healing="false"
data-cursed="false"
data-blessed="false"
style="font-size: 64px; font-family: 'Bebas Neue';">
PLAYER
</div>
<div style="margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;">
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="poisoned">Poisoned</button>
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="frozen">Frozen</button>
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="burning">Burning</button>
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="healing">Healing</button>
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="cursed">Cursed</button>
<button class="button" data-state data-state-trigger data-state-bind="statusDemo" data-state-toggle="blessed">Blessed</button>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Player with status effects -->
<div id="statusDemo"
data-state
data-state-toggles="poisoned,frozen,burning,healing,cursed,blessed"
data-poisoned="false"
data-frozen="false"
data-burning="false"
data-healing="false"
data-cursed="false"
data-blessed="false">
PLAYER
</div>
<!-- Buttons to toggle status effects -->
<button data-state
data-state-trigger
data-state-bind="statusDemo"
data-state-toggle="poisoned">
Poisoned
</button>
<button data-state
data-state-trigger
data-state-bind="statusDemo"
data-state-toggle="frozen">
Frozen
</button></pre>
</div>
<p><strong>Available status effects:</strong></p>
<ul>
<li><code>.state-poisoned</code> - Green hue pulse</li>
<li><code>.state-frozen</code> - Blue tint with shake</li>
<li><code>.state-burning</code> - Orange flicker</li>
<li><code>.state-healing</code> - Green sparkle</li>
<li><code>.state-cursed</code> - Dark pulsing</li>
<li><code>.state-blessed</code> - Golden glow</li>
</ul>
</div>
<!-- UI Feedback Example -->
<div class="example-section">
<h2>UI Notifications</h2>
<p>Feedback animations for success, error, warning messages.</p>
<h3>Live Demo</h3>
<div class="demo-preview">
<div id="notificationDemo"
data-state-toggles="success,error,warning"
data-success="false"
data-error="false"
data-warning="false"
style="font-size: 48px; font-family: 'Bebas Neue'; min-height: 60px;">
NOTIFICATION
</div>
<div style="margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;">
<button class="button" data-state data-state-trigger data-state-bind="notificationDemo" data-state-toggle="success">Success</button>
<button class="button" data-state data-state-trigger data-state-bind="notificationDemo" data-state-toggle="error">Error</button>
<button class="button" data-state data-state-trigger data-state-bind="notificationDemo" data-state-toggle="warning">Warning</button>
</div>
</div>
<h3>How This Demo Works</h3>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><!-- Notification element -->
<div id="notificationDemo"
data-state
data-state-toggles="success,error,warning"
data-success="false"
data-error="false"
data-warning="false">
NOTIFICATION
</div>
<!-- Buttons to trigger animations -->
<button data-state
data-state-trigger
data-state-bind="notificationDemo"
data-state-toggle="success">
Success
</button>
<button data-state
data-state-trigger
data-state-bind="notificationDemo"
data-state-toggle="error">
Error
</button></pre>
</div>
<p><strong>Available notification classes:</strong></p>
<ul>
<li><code>.state-success</code> - Bounce in</li>
<li><code>.state-error</code> - Shake animation</li>
<li><code>.state-warning</code> - Shake warning</li>
<li><code>.state-notification</code> - Slide in</li>
</ul>
</div>
<!-- Ready-to-Go Game Examples -->
<div class="example-section">
<h2>Complete UI System Examples</h2>
<p>Ready-to-use interactive components built with State.js alone. These examples demonstrate game mechanics, but the same patterns work for any interactive UI. Copy, paste, and customize!</p>
<!-- Health System with Regeneration -->
<h3>Health System</h3>
<div class="demo-preview">
<div id="regenDemo"
data-state-watch="health"
data-state-var="true"
data-health="50"
data-health-min="0"
data-health-max="100"
style="width: 400px;">
<div style="background: #222; padding: 20px; border-radius: 10px;">
<div style="margin-bottom: 15px; font-size: 18px;">
Health: <span data-state-display="health">50</span> / 100
</div>
<div style="background: #444; height: 30px; border-radius: 15px; overflow: hidden; margin-bottom: 15px;">
<div class="health-bar" style="background: linear-gradient(90deg, #700c0c 0%, #ff4444 50%, #44ff44 100%);
height: 100%;
width: var(--state-health-percent);
transition: width 0.3s;">
</div>
</div>
<div style="display: flex; gap: 10px; justify-content: center;">
<button class="button" data-state data-state-trigger data-state-bind="regenDemo" data-state-attr="health" data-state-value="25">Damage</button>
<button class="button" data-state data-state-trigger data-state-bind="regenDemo" data-state-attr="health" data-state-value="100">Heal</button>
</div>
</div>
</div>
</div>
<details style="margin: 20px 0;">
<summary style="cursor: pointer; padding: 10px; background: #1a1a1a; border-radius: 5px; font-weight: bold;">Show Code</summary>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><div id="player"
data-state-watch="health"
data-state-var="true"
data-health="100"
data-health-min="0"
data-health-max="100">
<!-- Health Display -->
<div>Health: <span data-state-display="health">100</span> / 100</div>
<!-- Health Bar -->
<div class="health-bar-container">
<div class="health-bar" style="width: var(--state-health-percent);"></div>
</div>
<!-- Controls -->
<button data-state data-state-trigger data-state-bind="player"
data-state-attr="health" data-state-value="50">Take Damage</button>
<button data-state data-state-trigger data-state-bind="player"
data-state-attr="health" data-state-value="100">Heal</button>
</div>
<style>
.health-bar-container {
background: #444;
height: 30px;
border-radius: 15px;
overflow: hidden;
}
.health-bar {
background: linear-gradient(90deg, red 0%, yellow 50%, green 100%);
height: 100%;
transition: width 0.3s;
}
/* Auto-regeneration animation */
.state-regenerating .health-bar {
animation: regen-pulse 2s infinite;
}
@keyframes regen-pulse {
0%, 100% { filter: brightness(1); }
50% { filter: brightness(1.5); }
}
</style></pre>
</div>
</details>
<!-- Clicker/Counter System -->
<h3>Clicker/Counter System (Zero JavaScript)</h3>
<div class="demo-preview">
<div id="clickerDemoAnim"
data-state
data-state-watch="score"
data-state-var="true"
data-score="0"
data-score-min="0"
data-score-max="100"
style="width: 400px; text-align: center;">
<div style="background: #222; padding: 30px; border-radius: 10px;">
<div style="font-size: 48px; font-family: 'Bebas Neue'; margin-bottom: 20px;">
<span data-state-display="score">0</span>
</div>
<div style="background: #444; height: 15px; border-radius: 10px; overflow: hidden; margin-bottom: 20px;">
<div style="background: linear-gradient(90deg, #700c0c 0%, #ff6b6b 100%);
height: 100%;
width: var(--state-score-percent);
transition: width 0.3s;">
</div>
</div>
<div style="display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;">
<button class="button"
data-state
data-state-trigger
data-state-bind="clickerDemoAnim"
data-state-attr="score"
data-state-increment="1">
+1
</button>
<button class="button"
data-state
data-state-trigger
data-state-bind="clickerDemoAnim"
data-state-attr="score"
data-state-increment="5">
+5
</button>
<button class="button"
data-state
data-state-trigger
data-state-bind="clickerDemoAnim"
data-state-attr="score"
data-state-increment="10">
+10
</button>
<button class="button"
data-state
data-state-trigger
data-state-bind="clickerDemoAnim"
data-state-attr="score"
data-state-value="0"
style="background: #444;">
Reset
</button>
</div>
<div style="margin-top: 20px; font-size: 14px; opacity: 0.7;">
Milestones at 25, 50, 75, and 100!
</div>
</div>
</div>
</div>
<details style="margin: 20px 0;">
<summary style="cursor: pointer; padding: 10px; background: #1a1a1a; border-radius: 5px; font-weight: bold;">Show Code</summary>
<div class="code-example">
<button class="copy-btn" onclick="copyCode(this)">Copy</button>
<pre><div id="clicker"
data-state
data-state-watch="score"
data-state-var="true"
data-score="0"
data-score-max="100">
<!-- Display -->
<div class="score-display"><span data-state-display="score">0</span></div>
<!-- Progress Bar -->
<div class="progress-bar" style="width: var(--state-score-percent);"></div>
<!-- Increment Buttons -->
<button data-state data-state-trigger data-state-bind="clicker"
data-state-attr="score" data-state-increment="1">+1</button>
<button data-state data-state-trigger data-state-bind="clicker"
data-state-attr="score" data-state-increment="5">+5</button>
<button data-state data-state-trigger data-state-bind="clicker"
data-state-attr="score" data-state-increment="10">+10</button>
<!-- Reset Button -->
<button data-state data-state-trigger data-state-bind="clicker"
data-state-attr="score" data-state-value="0">Reset</button>
</div>
<style>
/* Milestone celebrations using CSS alone */
#clicker[data-score="20"],
#clicker[data-score="30"],
#clicker[data-score="40"] {
animation: milestone-pulse 0.5s ease-out;
}
#clicker[data-score="50"] {
animation: milestone-burst 0.8s ease-out;
}
#clicker[data-score="100"] {
animation: victory-flash 1s ease-out;
}
@keyframes milestone-pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
@keyframes milestone-burst {
0% { transform: scale(1); filter: brightness(1); }
50% { transform: scale(1.1); filter: brightness(1.5); }
100% { transform: scale(1); filter: brightness(1); }
}
@keyframes victory-flash {
0%, 100% { filter: brightness(1); }
20%, 60% { filter: brightness(2) hue-rotate(90deg); }
40%, 80% { filter: brightness(0.5); }
}
</style></pre>
</div>
</details>
<!-- Inventory Toggle System -->
<h3>Inventory Toggle System</h3>
<div class="demo-preview">
<div id="inventoryDemo"
data-state-toggles="sword,shield,potion,key"
data-sword="false"
data-shield="false"
data-potion="false"
data-key="false"
style="width: 500px;">
<div style="background: #222; padding: 20px; border-radius: 10px;">
<h3 style="margin-top: 0;">Inventory</h3>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 20px;">
<div style="background: #333; padding: 15px; border-radius: 8px; text-align: center; transition: all 0.3s;">
<div style="font-size: 40px; margin-bottom: 10px;">⚔️</div>
<div>Sword</div>
<div style="font-size: 12px; opacity: 0.7; margin-top: 5px;">
Status: <span data-state-display="sword">false</span>
</div>
</div>
<div style="background: #333; padding: 15px; border-radius: 8px; text-align: center; transition: all 0.3s;">
<div style="font-size: 40px; margin-bottom: 10px;">🛡️</div>
<div>Shield</div>
<div style="font-size: 12px; opacity: 0.7; margin-top: 5px;">
Status: <span data-state-display="shield">false</span>
</div>
</div>
<div style="background: #333; padding: 15px; border-radius: 8px; text-align: center; transition: all 0.3s;">
<div style="font-size: 40px; margin-bottom: 10px;">🧪</div>
<div>Potion</div>