FlameF0X commited on
Commit
f165581
·
verified ·
1 Parent(s): a27d74b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -76,14 +76,22 @@ def get_messages_html(messages):
76
  </div>
77
  </div>
78
  """
79
- # Robust Auto-Scroll Script
80
  html += """
81
  </div>
82
  <script>
83
  (function() {
84
- var c = document.getElementById('chat-container');
85
- if(c) {
86
- c.scrollTo({ top: c.scrollHeight, behavior: 'smooth' });
 
 
 
 
 
 
 
 
87
  }
88
  })();
89
  </script>
 
76
  </div>
77
  </div>
78
  """
79
+ # Robust Auto-Scroll Script using MutationObserver
80
  html += """
81
  </div>
82
  <script>
83
  (function() {
84
+ const container = document.getElementById('chat-container');
85
+ if (container && !container.dataset.observed) {
86
+ const scrollDown = () => {
87
+ container.scrollTo({ top: container.scrollHeight, behavior: 'smooth' });
88
+ };
89
+ const observer = new MutationObserver(scrollDown);
90
+ observer.observe(container, { childList: true, subtree: true });
91
+ container.dataset.observed = "true";
92
+ scrollDown(); // Initial scroll
93
+ } else if (container) {
94
+ container.scrollTo({ top: container.scrollHeight, behavior: 'smooth' });
95
  }
96
  })();
97
  </script>