ソースを参照

add header effect

Falko Schindler 2 年 前
コミット
e4ea3caba9
1 ファイル変更24 行追加2 行削除
  1. 24 2
      main.py

+ 24 - 2
main.py

@@ -41,12 +41,34 @@ def add_head_html() -> None:
         }}
         }}
         </style>
         </style>
     ''')
     ''')
+    ui.add_head_html(f'''
+    <style>
+    .q-header {{
+        height: {HEADER_HEIGHT};
+        background-color: {ACCENT_COLOR};
+    }}
+    .q-header.fade {{
+        height: 50px;
+        background-color: {ACCENT_COLOR}d0;
+        backdrop-filter: blur(5px);
+    }}
+    </style>
+    <script>
+    window.onscroll = () => {{
+        const header = document.querySelector(".q-header");
+        if (document.documentElement.scrollTop > 50)
+            header.classList.add("fade");
+        else
+            header.classList.remove("fade");
+    }};
+    </script>
+    ''')
 
 
 
 
 def add_header() -> None:
 def add_header() -> None:
     with ui.header() \
     with ui.header() \
-            .classes('items-center') \
-            .style(f'background-color: {ACCENT_COLOR}; height: {HEADER_HEIGHT}; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1)'):
+            .classes('items-center duration-200 px-4', remove='q-pa-md') \
+            .style(f'box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1)'):
         ui.html((STATIC / 'happy_face.svg').read_text()).classes('w-8 stroke-white')
         ui.html((STATIC / 'happy_face.svg').read_text()).classes('w-8 stroke-white')
         with ui.link(target=index_page):
         with ui.link(target=index_page):
             ui.html((STATIC / 'nicegui_word.svg').read_text()).classes('w-24')
             ui.html((STATIC / 'nicegui_word.svg').read_text()).classes('w-24')