Lashtw commited on
Commit
d75b5f5
·
verified ·
1 Parent(s): 29e7e01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -23,45 +23,40 @@ image_data = [
23
  if 'page' not in st.session_state:
24
  st.session_state.page = 0
25
 
26
- # 使用容器來控制圖片和按鈕的佈局
27
  with st.container():
28
  # 顯示當前頁面的圖片,全屏顯示
29
  st.image(image_data[st.session_state.page]["path"],
30
  caption=image_data[st.session_state.page]["caption"],
31
  use_container_width=True)
32
 
33
- # 自訂 CSS 樣式,將按鈕浮動在圖片上方
34
  st.markdown("""
35
  <style>
36
- .button-container {
37
  position: absolute;
38
- top: 50%;
39
- width: 100%;
40
- display: flex;
41
- justify-content: space-between;
42
- padding: 0 20px;
43
- transform: translateY(-50%);
44
- }
45
- .stButton > button {
46
- background-color: rgba(255, 255, 255, 0.7);
47
- border: none;
48
- padding: 10px 20px;
49
- font-size: 16px;
50
  cursor: pointer;
51
  }
52
- .stButton > button:hover {
53
- background-color: rgba(255, 255, 255, 1);
 
 
 
54
  }
55
  </style>
56
  """, unsafe_allow_html=True)
57
 
58
- # 在圖片上浮動按鈕
59
- col1, col2 = st.columns([1, 1]) # 左右分欄
60
- with col1:
61
- if st.button("上一頁", key="prev") and st.session_state.page > 0:
62
  st.session_state.page -= 1
63
- with col2:
64
- if st.button("下一頁", key="next") and st.session_state.page < len(image_data) - 1:
65
  st.session_state.page += 1
66
 
67
  # 顯示當前頁數
 
23
  if 'page' not in st.session_state:
24
  st.session_state.page = 0
25
 
26
+ # 使用容器來控制圖片和點擊區域的佈局
27
  with st.container():
28
  # 顯示當前頁面的圖片,全屏顯示
29
  st.image(image_data[st.session_state.page]["path"],
30
  caption=image_data[st.session_state.page]["caption"],
31
  use_container_width=True)
32
 
33
+ # 自訂 CSS 樣式,將點擊區域設為透明並覆蓋圖片左右兩側
34
  st.markdown("""
35
  <style>
36
+ .click-area {
37
  position: absolute;
38
+ top: 0;
39
+ height: 100%;
40
+ width: 30%; /* 左右各占 30% 的點擊區域 */
41
+ background-color: rgba(0, 0, 0, 0); /* 完全透明 */
 
 
 
 
 
 
 
 
42
  cursor: pointer;
43
  }
44
+ .left-click {
45
+ left: 0;
46
+ }
47
+ .right-click {
48
+ right: 0;
49
  }
50
  </style>
51
  """, unsafe_allow_html=True)
52
 
53
+ # 分成左右兩欄作為點擊區域
54
+ col_left, col_center, col_right = st.columns([1, 2, 1]) # 左右各占 1,中間占 2
55
+ with col_left:
56
+ if st.button("", key="prev_area", help="點擊左側回到上一頁") and st.session_state.page > 0:
57
  st.session_state.page -= 1
58
+ with col_right:
59
+ if st.button("", key="next_area", help="點擊右側前往下一頁") and st.session_state.page < len(image_data) - 1:
60
  st.session_state.page += 1
61
 
62
  # 顯示當前頁數