Update app.py
Browse files
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 |
-
.
|
| 37 |
position: absolute;
|
| 38 |
-
top:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 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 |
-
.
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
</style>
|
| 56 |
""", unsafe_allow_html=True)
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
with
|
| 61 |
-
if st.button("
|
| 62 |
st.session_state.page -= 1
|
| 63 |
-
with
|
| 64 |
-
if st.button("
|
| 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 |
# 顯示當前頁數
|