Geek7 commited on
Commit
cedaed3
·
1 Parent(s): 6ce3856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -22
app.py CHANGED
@@ -1,27 +1,31 @@
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
- components.html(
5
- """
6
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
7
- <button onclick="triggerConfetti()">Click for Confetti</button>
 
 
 
 
 
 
 
 
8
 
9
- <script>
10
- // Function to trigger the confetti effect with random directions
11
- function triggerConfetti() {
12
- confetti({
13
- angle: randomInRange(55, 125),
14
- particleCount: randomInRange(50, 100),
15
- origin: { y: 0.6 },
16
- spread: randomInRange(50, 70),
17
- });
18
- }
19
 
20
- function randomInRange(min, max) {
21
- return Math.random() * (max - min) + min;
22
- }
23
- </script>
24
- """
25
- )
26
-
27
-
 
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
+ # JavaScript code for confetti animation
5
+ confetti_animation_script = """
6
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
7
+ <script>
8
+ function triggerConfetti() {
9
+ confetti({
10
+ angle: randomInRange(55, 125),
11
+ particleCount: randomInRange(50, 100),
12
+ origin: { y: 0.6 },
13
+ spread: randomInRange(50, 70),
14
+ });
15
+ }
16
 
17
+ function randomInRange(min, max) {
18
+ return Math.random() * (max - min) + min;
19
+ }
20
+ </script>
21
+ """
 
 
 
 
 
22
 
23
+ # Display the confetti animation script
24
+ components.html(confetti_animation_script, height=0)
25
+
26
+ # Button to trigger confetti using onclick method
27
+ confetti_button = st.button("Click for Confetti", on_click="triggerConfetti()")
28
+
29
+ if confetti_button:
30
+ st.empty() # Optional, clears the button after clicking
31
+ st.write("Confetti time!")