EasySci commited on
Commit
8d41099
·
1 Parent(s): d87ec9f

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +47 -3
app2.py CHANGED
@@ -33,9 +33,6 @@ def update_button_name(event):
33
  else:
34
  toggle_button.name = "filter2"
35
 
36
- # Attach the update_button_name function to the button's on_click event
37
- toggle_button.on_click(update_button_name)
38
-
39
  # Create a column layout for the buttons inside the toggleable sidebar
40
  buttons = pn.Column(
41
  button1, button2, button3,
@@ -43,6 +40,53 @@ buttons = pn.Column(
43
  css_classes=['hidden']
44
  )
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  # List to store the entered options
47
  loaded_list = TLDR.load_categories()
48
 
 
33
  else:
34
  toggle_button.name = "filter2"
35
 
 
 
 
36
  # Create a column layout for the buttons inside the toggleable sidebar
37
  buttons = pn.Column(
38
  button1, button2, button3,
 
40
  css_classes=['hidden']
41
  )
42
 
43
+ # Add the CSS style for the "Back to Top" button
44
+ css = """
45
+ <style>
46
+ .back-to-top {
47
+ display: none;
48
+ position: fixed;
49
+ bottom: 20px;
50
+ left: 20px;
51
+ width: 40px;
52
+ height: 40px;
53
+ border-radius: 50%;
54
+ background-color: #88d8b0;
55
+ color: white;
56
+ font-size: 24px;
57
+ text-align: center;
58
+ line-height: 40px;
59
+ cursor: pointer;
60
+ }
61
+
62
+ .back-to-top.show {
63
+ display: block;
64
+ }
65
+ </style>
66
+ """
67
+
68
+ # Append the CSS to the template
69
+ template.add_panel(css, raw=True)
70
+
71
+ # Create the "Back to Top" button
72
+ back_to_top_button = pn.widgets.Button(name="^", button_type="primary", css_classes=["back-to-top"], width=40, height=40)
73
+
74
+ # JavaScript callback for the "Back to Top" button
75
+ back_to_top_button.js_on_click(args={}, code="""
76
+ const scrollDuration = 300;
77
+ const scrollStep = -window.scrollY / (scrollDuration / 15);
78
+ const scrollInterval = setInterval(function() {
79
+ if (window.scrollY !== 0) {
80
+ window.scrollBy(0, scrollStep);
81
+ } else {
82
+ clearInterval(scrollInterval);
83
+ }
84
+ }, 15);
85
+ """)
86
+
87
+ # Add the "Back to Top" button to the template
88
+ template.main.append(back_to_top_button)
89
+
90
  # List to store the entered options
91
  loaded_list = TLDR.load_categories()
92