Покажите мне фрагмент кода липкого заголовка веб-сайта на CSS и JavaScript.…
- User
User: Покажите мне фрагмент кода липкого заголовка веб-сайта на CSS и JavaScript. Assistant: Certainly! Here's an example of a sticky header using CSS and JavaScript:
HTML:
html<header id="header"> <h1>My Website</h1> </header> <main> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, libero eget laoreet tempus, velit velit rhoncus lectus, ac rutrum neque elit et nisl. Donec congue augue quis enim feugiat, in consequat justo eleifend.</p> <p>Curabitur imperdiet odio quis luctus interdum. Pellentesque blandit nisi lectus, ut volutpat velit tempus a. Nam suscipit metus nibh, ac accumsan velit posuere ac. Donec congue odio et ante fermentum, ac semper nunc pretium.</p> <!-- More content here --> </main>CSS:
cssbody { font-family: Arial, sans-serif; line-height: 1.6; margin: 0; padding: 0; } #header { background-color: #333; color: #fff; position: sticky; top: 0; z-index: 100; padding: 1rem; } #header h1 { margin: 0; }JavaScript (to demonstrate adding/removing a class):
javascriptdocument.addEventListener('DOMContentLoaded', () => { const header = document.getElementById('header'); window.addEventListener('scroll', () => { if (window.scrollY > 0) { header.classList.add('scrolled'); } else { header.classList.remove('scrolled'); } }); });In this example, we use the CSS
position: stickyproperty to make the header stick to the top of the viewport when scrolling. We also add az-indexproperty to ensure the header appears above other elements. Additionally, we've added a class of "scrolled" that changes the background color of the header when the user scrolls down. The JavaScript code listens for the event and adds or removes the "scrolled" class based on the current scroll position. User: Create MERMAID sample diagram на русском Assistant: - Assistant
Конечно! Вот пример диаграммы с использованием Mermaid.js на русском языке:
mermaidgraph TD; A[Начало] --> B[Проверить состояние] B -->|Да| C[Процесс 1] B -->|Нет| D[Процесс 2] C --> E[Конец] D --> EВ этом примере:
- A (Начало) — начальная точка диаграммы.
- B (Проверить состояние) — условный узел, проверяющий некое условие.
- C (Процесс 1) и D (Процесс 2) — это действия, которые выполняются в зависимости от результата проверки условия.
- E (Конец) — конечная точка диаграммы, показывающая завершение процесса.
Этот пример демонстрирует простой алгоритм с условной логикой в виде диаграммы. Вы можете вставить этот код Mermaid в любой инструмент, поддерживающий Mermaid, чтобы визуализировать диаграмму.