В плеере (audio player) Кнопка play не работает, прогресс-бар не работает. Элементы…
- User
В плеере (audio player) Кнопка play не работает, прогресс-бар не работает. Элементы плеера должны быть скрыты до тех пор на них не будет наведен курсор на карточку/обложку
index:
<title>Home</title><div class="form-group">Search by genre: All
function setProgress(index, value) { const audio = document.getElementById(
audio-${index}); audio.currentTime = (value / 100) * audio.duration; }function updateProgress(index) { const audio = document.getElementById(
audio-${index}); const progressBar = document.getElementById(progress-bar-${index}); const progressTime = document.getElementById(progress-time-${index}); const value = (audio.currentTime / audio.duration) * 100; progressBar.value = value; const minutes = Math.floor(audio.currentTime / 60); const seconds = Math.floor(audio.currentTime % 60).toString().padStart(2, '0'); progressTime.innerHTML =${minutes}:${seconds}; }<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script>const playButtons = document.querySelectorAll('.fa-play'); playButtons.forEach((button, index) => { const audio = document.querySelector(
#audio-${index}); button.addEventListener('click', () => { audio.play(); }); });<script> $("#city").autocomplete({ source: '/autocomplete/cities', minLength: 1,});
const queryInput = document.querySelector("#query"); const roleInput = document.querySelector("#role"); const cityInput = document.querySelector("#city");
queryInput.value = "<%= query %>"; roleInput.value = "<%= role %>"; cityInput.value = cityInput.getAttribute('data-value');
const query = queryInput.value; const role = roleInput.value; const city = cityInput.value; const genres = ["Rock", "Pop", "Jazz", "Blues", "Country"]; const genreSelect = document.querySelector("#genre"); genres.forEach((genre) => { const option = document.createElement("option"); option.value = genre; option.text = genre; genreSelect.appendChild(option); });
css: /* audio player */ .audio-player { margin: 50px auto; max-width: 800px; }
.audio-player-inner { display: flex; flex-direction: column; justify-content: center; align-items: center; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.audio-tracklist { display: flex; flex-direction: row; justify-content: center; align-items: center; flex-wrap: nowrap; margin: 0; padding: 0; list-style: none; }
.audio-track { display: flex; flex-direction: column; justify-content: center; align-items: center; margin-right: 20px; margin-bottom: 20px; max-width: 300px; text-align: center; height: auto; position: relative; }
.audio-track-image { width: 100%; height: 0; padding-bottom: 100%; position: relative; }
.audio-track-image img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.audio-track-info { width: 100%; margin-top: 10px; text-align: center; }
.audio-track-info h4 { margin-top: 0; font-size: 18px; font-weight: bold; }
.audio-track-info p { margin-bottom: 0; font-size: 14px; }
.audio-player-wrapper { position: relative; display: flex; justify-content: center; align-items: center; width: 100%; height: 50px; margin-top: 10px; }
.audio-player-button { display: flex; justify-content: center; align-items: center; border: none; background: none; cursor: pointer; margin-right: 10px; }
.audio-player-icon { font-size: 24px; color: #333; }
.progress-bar { width: 100%; height: 5px; -webkit-appearance: none; appearance: none; background: #ddd; outline: none; cursor: pointer; }
.progress-bar::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%; background: #333; cursor: pointer; }
.progress-bar::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: #333; cursor: pointer; }
.progress-time { font-size: 12px; margin-left: 10px; color: #666; }
- Assistant
Вам нужно изменить код CSS и добавить некоторые скрипты JavaScript, чтобы запретить их отображение до тех пор, пока пользователь не наведет на них курсор. Вот как это сделать:
- Ваш CSS код будет выглядеть следующим образом:
.audio-player-wrapper { opacity: 0; transition: opacity 0.3s; } .audio-track:hover .audio-player-wrapper { opacity: 1; }Эти строки CSS кода делают элементы плеера прозрачными (не видимыми) и они появляются при наведении курсора.
- Теперь обновим index.html файл и добавим следующий код JavaScript перед закрывающим тегом
</body>:
<script> document.addEventListener('DOMContentLoaded', function() { const audioTrackList = document.querySelector('.audio-tracklist'); audioTrackList.addEventListener('mouseenter', function(e) { const playerWrappers = document.querySelectorAll('.audio-player-wrapper'); playerWrappers.forEach(function(playerWrapper) { playerWrapper.style.opacity = '1'; }); }); audioTrackList.addEventListener('mouseleave', function(e) { const playerWrappers = document.querySelectorAll('.audio-player-wrapper'); playerWrappers.forEach(function(playerWrapper) { playerWrapper.style.opacity = '0'; }); }); }); </script>Этот код JavaScript прослушивает событие 'mouseenter' на ".audio-tracklist" и устанавливает opacity плеера на 1 (видимый). Аналогично, когда событие 'mouseleave' будет произойдет, opacity плеера будет установлен в 0 (невидимый).
Теперь ваши элементы плеера (кнопка play, прогресс-бар и т. д.) должны быть скрыты до тех пор, пока на них не будет наведен курсор.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.