<!DOCTYPE html> <html lang="en"> <meta name="viewport" content="width=device-width,…
- User
<meta charset="UTF-8"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://kit.fontawesome.com/3edae8f033.js" crossorigin="anonymous"></script> <style>@keyframes up { 0% { transform: translateY(0%); }
50% { transform: translateY(100px); } 100% { transform: translateY(0); }}
@keyframes across { from { right: 0%; }
to { right: 100%; }}
.fa-snowflake { color: #ecf2f8; }
.snow { width: 100%; height: 100%; position: absolute; }
.snowflake { animation-name: fall, shake; animation-duration: 10s, 5s; animation-timing-function: linear, ease-in-out; animation-iteration-count: infinite, infinite; position: fixed; left: 200px; z-index: 1; }
@keyframes fall { 0% { top: -10%; }
100% { top: 98%; }}
@keyframes shake { 0% { transform: translatex(0); } 50% { transform: translatex(50px); } 100% { transform: translatex(0); } }
:root { --primary-color: {{ current_user.theme_primary_color if current_user.is_authenticated else '#007bff' }}; --secondary-color: {{ current_user.theme_secondary_color if current_user.is_authenticated else '#6c757d' }}; --background-color: {{ current_user.theme_background_color if current_user.is_authenticated else '#ffffff' }}; } body { background-color: var(--background-color); color: var(--secondary-color); } p { transition: color 0.3s; color: var(--secondary-color); } .navbar, .btn-primary { background-color: var(--primary-color) !important; } .btn-secondary { background-color: var(--secondary-color) !important; } a { color: var(--primary-color); } a:hover { color: var(--secondary-color); } /* Example for card components */ .card { background-color: var(--background-color); border: 1px solid var(--secondary-color); color: var(--secondary-color); } </style> <style type="text/css">/* Styles for the avatar */ .avatar { position: relative; display: inline-block; cursor: pointer; }
.avatar img { border-radius: 50%; width: 50px; height: 50px; } /* Styles for the dropdown */ .dropdown { display: none; position: absolute; right: 0; background-color: white; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; min-width: 160px; max-height: 0; overflow: hidden; transition: max-height 0.8s ease-out; } .navbar { z-index: 1040; /* Ensure navbar is on top */}
.dropdown-menu { height: 260px; /* Adjust based on navbar height */ }
.collapse { overflow: hidden; /* Ensures no overflow from expanded content */ } .dropdown a { color: black; padding: 12px 16px; text-decoration: none; display: block; }
.dropdown a:hover { background-color: #ddd; } .show { display: block; max-height: 770px; /* Adjust based on content height */ } </style> <title>{{ title }}</title> </head> <body>{% if current_user.selected_theme_id in [2, 17] %} {% endif %}
<script> document.addEventListener("DOMContentLoaded", function() { const snowflakesCount = 80; // Adjust the number of snowflakes here const snowContainer = document.querySelector('.snow'); for (let i = 0; i < snowflakesCount; i++) { const snowflake = document.createElement('div'); snowflake.className = 'snowflake'; snowflake.innerHTML = '<i class="fa-regular fa-snowflake"></i>'; // Randomize the position const randomX = Math.random() * 100; // Random position in viewport width snowflake.style.left = `${randomX}vw`; // Randomize animation duration const randomDuration = Math.random() * 10 + 5; // Random time between 5 and 15 seconds snowflake.style.animationDuration = `${randomDuration}s`; // Randomize rotation const randomRotation = Math.random() * 360; // Random angle snowflake.style.transform = `rotate(${randomRotation}deg)`; snowContainer.appendChild(snowflake); } }); </script> <style> :root { --primary-color: {{ current_user.theme_primary_color if current_user.is_authenticated else '#007bff' }}; --secondary-color: {{ current_user.theme_secondary_color if current_user.is_authenticated else '#6c757d' }}; --background-color: {{ current_user.theme_background_color if current_user.is_authenticated else '#ffffff' }}; } body { background-color: var(--background-color); color: var(--secondary-color); } .navbar, .btn-primary { background-color: var(--primary-color) !important; } .btn-secondary { background-color: var(--secondary-color) !important; } a { color: var(--primary-color); } a:hover { color: var(--secondary-color); } .card { background-color: var(--background-color); border: 1px solid var(--secondary-color); color: var(--secondary-color); } </style>{% if show_birthday_modal %} <div class="modal fade" id="birthdayModal" tabindex="-1" role="dialog" aria-labelledby="birthdayModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="birthdayModalLabel">С днём рождения!</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p>Мы желаем вам очень счастливого дня рождения! 🎉</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal">Спасибо!</button> </div> </div> </div> </div> {% endif %} <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script> document.addEventListener("DOMContentLoaded", function() { {% if show_birthday_modal %} $('#birthdayModal').modal('show'); {% endif %} }); </script> <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top"> <div class="container-fluid"> <a class="navbar-brand mb-0 h1" href="/"> <img src="/static/img/vhs.png" alt="" width="201 height="35"> </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link" href="/tools">Инструменты</a> </li> {% if authenticated %} <li class="nav-item"> <a class="nav-link" href="/people">Подписки</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('users') }}">Все пользователи</a>{% if current_user.is_admin %} <li class="nav-item"> <a class="nav-link" href="{{ url_for('admin_users') }}">Админ</a> </li> {% endif %} <li class="nav-item"> <a class="nav-link" href="/about">Про сайт</a> </li> {% else %} <li class="nav-item"> <a class="nav-link" href="/login">Войти</a> </li> <li class="nav-item"> <a class="nav-link" href="/register">Зарегаться</a> </li> <li class="nav-item"> <a class="nav-link" href="/about">Про сайт</a> </li> {% endif %} <li class="nav-item"> <a class="nav-link" href="/tracks">AudioBox</a> </li> <li> </li> </ul> {% if authenticated %} <div class="avatar" onclick="toggleDropdown()"> <img src="{{ url_for('static', filename='avatars/' ~ current_user.avatar) }}" alt="Avatar" style="width:60px; height:60px;"><div id="toast-container" class="position-fixed bottom-0 end-0 p-3" style="z-index: 11"></div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.6.1/socket.io.js"></script> <script> // Initialize SocketIO connection var socket = io(); socket.on('notify', function (data) { showToast(data.message); }); function showToast(message) { var container = document.getElementById('toast-container'); var toastHTML = ` <div class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true"> <div class="d-flex"> <div class="toast-body">${message}</div> <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> `; container.insertAdjacentHTML('beforeend', toastHTML); var toastElement = container.lastElementChild; var toast = new bootstrap.Toast(toastElement); toast.show(); // Optional: remove after display to prevent clutter toastElement.addEventListener('hidden.bs.toast', function () { toastElement.remove(); }); } </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.6.1/socket.io.js"></script> <style> div { backdrop-filter: blur(0px); } </style> </body> - Assistant
To adjust the size of the "Add Video" icon in the mobile version of your webpage, you need to add some responsive styles to control its size based on the viewport. Here are a few ways to do this:
1. CSS Media Queries
You can use CSS media queries to change the size of the icon based on the screen size. Add the following styles inside your existing
<style>tags in the<head>section of your HTML:/* Add this CSS */ @media (max-width: 576px) { /* Adjust max-width according to your design */ .add-video-icon { width: 24px; /* Reduced width for mobile */ height: 24px; /* Reduced height for mobile */ } }2. Modify the SVG Directly
If you want to explicitly set the size when including the SVG, you could modify the line where you include the SVG for the "Add Video" functionality. Change it like this:
<a href="/add_video"> <svg xmlns="http://www.w3.org/2000/svg" height="40" viewBox="0 0 24 24" width="40" focusable="false" aria-hidden="true" class="add-video-icon"><path d="M14 13h-3v3H9v-3H6v-2h3V8h2v3h3v2zm3-7H3v12h14v-6.39l4 1.83V8.56l-4 1.83V6m1-1v3.83L22 7v8l-4-1.83V19H2V5h16z"></path></svg> </a>3. Use Bootstrap Classes
If you're using Bootstrap, you might already have utility classes available. You can utilize the
img-fluidclass for responsive images or set width and height classes. Example:<a href="/add_video"> <svg xmlns="http://www.w3.org/2000/svg" height="40" viewBox="0 0 24 24" width="40" class="img-fluid" focusable="false" aria-hidden="true"><path d="M14 13h-3v3H9v-3H6v-2h3V8h2v3h3v2zm3-7H3v12h14v-6.39l4 1.83V8.56l-4 1.83V6m1-1v3.83L22 7v8l-4-1.83V19H2V5h16z"></path></svg> </a>4. Run Your Changes
Once you've added the necessary CSS or modified the SVG element as described above, make sure to test the mobile layout. Check if the icon size has been reduced as expected. Adjust the sizes further if needed.
Note
Remember to clear your browser cache or use incognito mode to see the changes reflected immediately after updating the code.
- User
<meta charset="UTF-8"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://kit.fontawesome.com/3edae8f033.js" crossorigin="anonymous"></script> <style>@keyframes up { 0% { transform: translateY(0%); }
50% { transform: translateY(100px); } 100% { transform: translateY(0); }}
@keyframes across { from { right: 0%; }
to { right: 100%; }}
.fa-snowflake { color: #ecf2f8; }
.snow { width: 100%; height: 100%; position: absolute; }
.snowflake { animation-name: fall, shake; animation-duration: 10s, 5s; animation-timing-function: linear, ease-in-out; animation-iteration-count: infinite, infinite; position: fixed; left: 200px; z-index: 1; }
@keyframes fall { 0% { top: -10%; }
100% { top: 98%; }}
@keyframes shake { 0% { transform: translatex(0); } 50% { transform: translatex(50px); } 100% { transform: translatex(0); } }
:root { --primary-color: {{ current_user.theme_primary_color if current_user.is_authenticated else '#007bff' }}; --secondary-color: {{ current_user.theme_secondary_color if current_user.is_authenticated else '#6c757d' }}; --background-color: {{ current_user.theme_background_color if current_user.is_authenticated else '#ffffff' }}; } body { background-color: var(--background-color); color: var(--secondary-color); } p { transition: color 0.3s; color: var(--secondary-color); } .navbar, .btn-primary { background-color: var(--primary-color) !important; } .btn-secondary { background-color: var(--secondary-color) !important; } a { color: var(--primary-color); } a:hover { color: var(--secondary-color); } /* Example for card components */ .card { background-color: var(--background-color); border: 1px solid var(--secondary-color); color: var(--secondary-color); } </style> <style type="text/css">/* Styles for the avatar */ .avatar { position: relative; display: inline-block; cursor: pointer; }
.avatar img { border-radius: 50%; width: 50px; height: 50px; } /* Styles for the dropdown */ .dropdown { display: none; position: absolute; right: 0; background-color: white; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; min-width: 160px; max-height: 0; overflow: hidden; transition: max-height 0.8s ease-out; } .navbar { z-index: 1040; /* Ensure navbar is on top */}
.dropdown-menu { height: 260px; /* Adjust based on navbar height */ }
.collapse { overflow: hidden; /* Ensures no overflow from expanded content */ } .dropdown a { color: black; padding: 12px 16px; text-decoration: none; display: block; }
.dropdown a:hover { background-color: #ddd; } .show { display: block; max-height: 770px; /* Adjust based on content height */ } </style> <title>{{ title }}</title> </head> <body>{% if current_user.selected_theme_id in [2, 17] %} {% endif %}
<script> document.addEventListener("DOMContentLoaded", function() { const snowflakesCount = 80; // Adjust the number of snowflakes here const snowContainer = document.querySelector('.snow'); for (let i = 0; i < snowflakesCount; i++) { const snowflake = document.createElement('div'); snowflake.className = 'snowflake'; snowflake.innerHTML = '<i class="fa-regular fa-snowflake"></i>'; // Randomize the position const randomX = Math.random() * 100; // Random position in viewport width snowflake.style.left = `${randomX}vw`; // Randomize animation duration const randomDuration = Math.random() * 10 + 5; // Random time between 5 and 15 seconds snowflake.style.animationDuration = `${randomDuration}s`; // Randomize rotation const randomRotation = Math.random() * 360; // Random angle snowflake.style.transform = `rotate(${randomRotation}deg)`; snowContainer.appendChild(snowflake); } }); </script> <style> :root { --primary-color: {{ current_user.theme_primary_color if current_user.is_authenticated else '#007bff' }}; --secondary-color: {{ current_user.theme_secondary_color if current_user.is_authenticated else '#6c757d' }}; --background-color: {{ current_user.theme_background_color if current_user.is_authenticated else '#ffffff' }}; } body { background-color: var(--background-color); color: var(--secondary-color); } .navbar, .btn-primary { background-color: var(--primary-color) !important; } .btn-secondary { background-color: var(--secondary-color) !important; } a { color: var(--primary-color); } a:hover { color: var(--secondary-color); } .card { background-color: var(--background-color); border: 1px solid var(--secondary-color); color: var(--secondary-color); } </style>{% if show_birthday_modal %} <div class="modal fade" id="birthdayModal" tabindex="-1" role="dialog" aria-labelledby="birthdayModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="birthdayModalLabel">С днём рождения!</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p>Мы желаем вам очень счастливого дня рождения! 🎉</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal">Спасибо!</button> </div> </div> </div> </div> {% endif %} <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script> document.addEventListener("DOMContentLoaded", function() { {% if show_birthday_modal %} $('#birthdayModal').modal('show'); {% endif %} }); </script> <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top"> <div class="container-fluid"> <a class="navbar-brand mb-0 h1" href="/"> <img src="/static/img/vhs.png" alt="" width="201 height="35"> </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link" href="/tools">Инструменты</a> </li> {% if authenticated %} <li class="nav-item"> <a class="nav-link" href="/people">Подписки</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('users') }}">Все пользователи</a>{% if current_user.is_admin %} <li class="nav-item"> <a class="nav-link" href="{{ url_for('admin_users') }}">Админ</a> </li> {% endif %} <li class="nav-item"> <a class="nav-link" href="/about">Про сайт</a> </li> {% else %} <li class="nav-item"> <a class="nav-link" href="/login">Войти</a> </li> <li class="nav-item"> <a class="nav-link" href="/register">Зарегаться</a> </li> <li class="nav-item"> <a class="nav-link" href="/about">Про сайт</a> </li> {% endif %} <li class="nav-item"> <a class="nav-link" href="/tracks">AudioBox</a> </li> <li> </li> </ul> {% if authenticated %} <div class="avatar" onclick="toggleDropdown()"> <img src="{{ url_for('static', filename='avatars/' ~ current_user.avatar) }}" alt="Avatar" style="width:60px; height:60px;"><div id="toast-container" class="position-fixed bottom-0 end-0 p-3" style="z-index: 11"></div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.6.1/socket.io.js"></script> <script> // Initialize SocketIO connection var socket = io(); socket.on('notify', function (data) { showToast(data.message); }); function showToast(message) { var container = document.getElementById('toast-container'); var toastHTML = ` <div class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true"> <div class="d-flex"> <div class="toast-body">${message}</div> <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> `; container.insertAdjacentHTML('beforeend', toastHTML); var toastElement = container.lastElementChild; var toast = new bootstrap.Toast(toastElement); toast.show(); // Optional: remove after display to prevent clutter toastElement.addEventListener('hidden.bs.toast', function () { toastElement.remove(); }); } </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.6.1/socket.io.js"></script> <style> div { backdrop-filter: blur(0px); } </style> </body> - Assistant
To address the issues regarding the avatar dropdown and the top bar appearing strangely when viewing on mobile devices, I'll provide CSS adjustments and improvements to the JavaScript logic. Below are the steps you can take to improve the functionality and appearance of the avatar dropdown as well as ensure the navigation bar behaves as expected.
1. Fixing the Avatar Dropdown
To make the avatar dropdown look better and work more effectively, you should set its styles, including width and appropriate positioning, in a responsive way. Here’s how to do it:
CSS Improvements:
- Adjust the CSS for the dropdown to position it correctly under the avatar and make it responsive.
- Introduce transition effects for smoother dropdown visibility.
/* Improved dropdown styles */ .dropdown { display: none; /* Initially hidden */ position: absolute; right: 0; background-color: white; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; min-width: 160px; transition: all 0.3s ease; /* Smooth transition for dropdown visibility */ } .show { display: block; /* Show the dropdown */ } .avatar { position: relative; /* Ensure relative positioning for dropdown */ } /* Mobile responsiveness */ @media (max-width: 576px) { .dropdown { min-width: 100%; /* Allow dropdown to take full width on mobile */ } }2. Preventing Unwanted Dropdown Visibility
Ensure the dropdown doesn't open unexpectedly. This often occurs when using Bootstrap's JavaScript alongside custom scripts. Ensure that dropdown toggling is appropriately handled to not trigger it on page load.
JavaScript Improvements:
You already have a function to toggle the dropdown. Ensure that the dropdown only opens on click events and doesn't flash on page load. You might have redundant socket.io scripts as well. Ensure you only include them once.
Here’s how to refine the JavaScript:
<script> function toggleDropdown() { const dropdown = document.getElementById('dropdownMenu'); dropdown.classList.toggle('show'); } // Close the dropdown if the user clicks outside of it window.onclick = function(event) { const dropdown = document.getElementById('dropdownMenu'); if (!event.target.matches('.avatar img') && !dropdown.contains(event.target)) { if (dropdown.classList.contains('show')) { dropdown.classList.remove('show'); } } } </script>3. Improving the Navigation Bar Mobile Experience
To ensure that the top navigation bar works well when collapsed, ensure you're using the Bootstrap classes correctly:
- Verify you're using the Bootstrap
navbar-togglerfeatures for mobile view. - Ensure the navbar toggler correctly handles the opening and closing of the menu without displaying issues.
Final Integration
With the above suggestions, here's how you would integrate the improvements in your HTML:
<style> /* Include the styles from above here */ </style> <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top"> <div class="container-fluid"> <a class="navbar-brand mb-0 h1" href="/"> <img src="/static/img/vhs.png" alt="" width="201" height="35"> </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <!-- Links here --> </ul> {% if authenticated %} <div class="avatar" onclick="toggleDropdown()"> <img src="{{ url_for('static', filename='avatars/' ~ current_user.avatar) }}" alt="Avatar" style="width:60px; height:60px;"> <div class="dropdown" id="dropdownMenu"> <a href="/settings">Настройки</a> <a href="/user/{{ current_user.id }}">Моя страница</a> <a href="/favorite">Избранное</a> <a href="/logout">Выйти</a> </div> </div> {% endif %} </div> </div> </nav>Test Your Changes
- Open your page on a mobile device or use a responsive design tool in your browser to view it.
- Observe if the dropdown appears only when you click the avatar and closes when you click outside.
- Adjust breakpoints or styles further as per your design preference.
By following these steps, your avatar dropdown functionality and overall navigation bar should become more user-friendly and visually appealing on mobile devices.