georad commited on
Commit
9a10dbf
·
verified ·
1 Parent(s): 02ac1f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -31,24 +31,34 @@ about_page = st.Page(
31
  icon=":material/info:",
32
  default=False)
33
 
 
 
 
34
 
35
  # Create scrollable content
36
  for i in range(100):
37
  st.write(f"This is scrollable content line {i}")
38
 
39
- # Create an anchor at the bottom
40
- st.markdown('<div id="bottom"></div>', unsafe_allow_html=True)
41
-
42
- # Add JavaScript to automatically scroll to the anchor
43
- st.markdown("""
44
- <script>
45
- // Set a timeout to ensure the page has loaded
46
- setTimeout(function() {
47
- // Scroll to the bottom anchor
48
- document.getElementById('bottom').scrollIntoView();
49
- }, 500);
50
- </script>
51
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
52
 
53
 
54
  # --- NAVIGATION SETUP ---
 
31
  icon=":material/info:",
32
  default=False)
33
 
34
+ # --- Automatic Scrolling Approach ---
35
+ # Add a checkbox to control auto-scrolling
36
+ auto_scroll = st.sidebar.checkbox("Auto-scroll to bottom", value=True)
37
 
38
  # Create scrollable content
39
  for i in range(100):
40
  st.write(f"This is scrollable content line {i}")
41
 
42
+ # Add a manual scroll button at both top and bottom for convenience
43
+ if st.button("Scroll to Bottom") or auto_scroll:
44
+ # Create a link target
45
+ st.markdown('''
46
+ <a name="bottom"></a>
47
+ ''', unsafe_allow_html=True)
48
+
49
+ # Use Streamlit's HTML component to execute the scroll
50
+ st.components.v1.html('''
51
+ <script>
52
+ // Use the iframe parent to scroll the main content area
53
+ window.parent.document.querySelector('section.main').scrollTo({
54
+ top: window.parent.document.querySelector('section.main').scrollHeight,
55
+ behavior: 'smooth'
56
+ });
57
+ </script>
58
+ ''', height=0)
59
+
60
+ # Add some text at the bottom as a visual indicator
61
+ st.write("You've reached the bottom!")
62
 
63
 
64
  # --- NAVIGATION SETUP ---