nagasurendra commited on
Commit
bc3b48c
·
verified ·
1 Parent(s): 20e3c97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -344,7 +344,7 @@ def app():
344
  menu_output = gr.HTML(value=filter_menu("All"))
345
 
346
  # Button to navigate to Cart Page
347
- view_cart_button = gr.Button("View Cart")
348
 
349
  # Empty div box with 300px height
350
  empty_div = gr.HTML('<div style="height: 300px;"></div>')
@@ -442,6 +442,30 @@ def app():
442
  lambda: (gr.update(visible=True), gr.update(visible=False)),
443
  outputs=[menu_section, cart_section],
444
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  return demo
447
 
 
344
  menu_output = gr.HTML(value=filter_menu("All"))
345
 
346
  # Button to navigate to Cart Page
347
+ view_cart_button = gr.Button("View Cart", elem_id="view-cart-button")
348
 
349
  # Empty div box with 300px height
350
  empty_div = gr.HTML('<div style="height: 300px;"></div>')
 
442
  lambda: (gr.update(visible=True), gr.update(visible=False)),
443
  outputs=[menu_section, cart_section],
444
  )
445
+ # Inject JavaScript for Scrolling to Top
446
+ gr.HTML("""
447
+ <script>
448
+ function addToCart() {
449
+ alert("Item added to cart!");
450
+ document.getElementById('modal').style.display = 'none';
451
+ }
452
+
453
+ function closeModal() {
454
+ document.getElementById('modal').style.display = 'none';
455
+ }
456
+
457
+ document.addEventListener("DOMContentLoaded", function () {
458
+ const viewCartButton = document.querySelector("#view-cart-button");
459
+ if (viewCartButton) {
460
+ viewCartButton.addEventListener("click", function () {
461
+ setTimeout(() => {
462
+ window.scrollTo({ top: 0, behavior: "smooth" });
463
+ }, 200);
464
+ });
465
+ }
466
+ });
467
+ </script>
468
+ """)
469
 
470
  return demo
471