Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

После нажатия на кнопку play в плеере ( ) появляется горизонтальная черная полоса,…

  1. User

    После нажатия на кнопку play в плеере ( ) появляется горизонтальная черная полоса, которая при включении расширяется, при выключении сужается. Такое ощущение, что это часть иконки, однако такое поведение будет у любой fa иконки, какую бы я не поставил. Это какой-то артефакт. Кнопка работает только на включение, но выключение не работает.

    index:

    if (audio.paused) { audio.play(); icon.classList.remove("fa-play"); icon.classList.add("fa-stop"); } else { audio.pause(); icon.classList.remove("fa-stop"); icon.classList.add("fa-play"); } }

    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);constprogressBar=document.getElementById(progress−bar−{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 formattedTime = formatTime(audio.currentTime); progressTime.innerHTML = formattedTime; }

    function formatTime(time) { const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); const formattedSeconds = seconds < 10 ? 0seconds:seconds;return{seconds} : seconds; return {minutes}:${formattedSeconds}; } 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; transition: transform 0.3s; overflow: hidden; /* добавлено свойство */ }

    .audio-track:hover { transform: scale(1.05); }

    .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; filter: brightness(100%); transition: filter 0.3s; }

    .audio-track:hover img { filter: brightness(70%); }

    .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 { opacity: 0; transition: opacity 0.3s; }

    .audio-track:hover .audio-player-wrapper { opacity: 1; }

    .audio-player-button { display: flex; justify-content: center; align-items: center; border: none; background: none; cursor: pointer; margin: 0 auto; }

    .audio-player-icon { font-size: 24px; margin-top:-250px;

    color: #fff; position: relative; /* добавить свойство position / z-index: 1; / добавить свойство z-index */ }

    .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; }

    input[type=range]::-webkit-slider-runnable-track { background: transparent; border: none; }

  2. Assistant

    The issue you are experiencing is likely caused by the font-awesome icons. A common solution to fix this issue is to set the 'font-weight' CSS property to 900 for the .audio-player-icon class.

    Modify your CSS:

    .audio-player-icon {
      font-size: 24px;
      margin-top:-250px;
      color: #fff;
      position: relative; /* добавить свойство position */
      z-index: 1; /* добавить свойство z-index */
      font-weight: 900; /* add font-weight property */
    }
    

    Additionally, your JavaScript code contains errors caused by incorrect usage of template literals. You should replace the getElementById and string concatenation with proper template literals using backticks () and ${}`.

    Modify your JavaScript:

    function togglePlay(index) {
      const audio = document.getElementById(`audio-${index}`);
      const button = document.querySelectorAll('.audio-player-button')[index];
      const icon = document.querySelectorAll('.audio-player-icon')[index];
    
      //...
    }
    
    function setProgress(index, value) {
      const audio = document.getElementById(`audio-${index}`);
      //...
    }
    
    function updateProgress(index) {
      const audio = document.getElementById(`audio-${index}`);
      const progressBar = document.getElementById(`progress-bar-${index}`);
      const progressTime = document.getElementById(`progress-time-${index}`);
      //...
    }
    
    function formatTime(time) {
      const minutes = Math.floor(time / 60);
      const seconds = Math.floor(time % 60);
      const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds;
      return `${minutes}:${formattedSeconds}`;
    }
    

    Finally, make sure to import the CSS file for Font Awesome in your HTML file:

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    

    If the issue still persists, please let me know so I can help you further with a different approach.