Отключить появление / исчезновение звука - PullRequest
1 голос
/ 15 апреля 2020

У меня есть сценарий воспроизведения звука, с зацикливанием, но когда звук начинается и заканчивается, эффект затухания. мне нужно без замирания эффекта зацикливания. вот мой код, где варианты затухания и как отключить? помогите пожалуйста

'use-strict' window.addEventListener ('load', function () {

var dom = $('#embed-audio-01');

var audios = {
    one : new Audio('audio/city_airplane.ogg'),
    two : new Audio('audio/city_washing_machine.ogg'),
    thr : new Audio('audio/test.mp3')
}

dom.find('.audio__volume').on('input', function(){
    var data = $(this).closest('.audio').attr('data-audio'),
        volume = $(this).val() / 100;
    audios[data].volume = volume;
});

dom.find('.audio__media').click(function(){
    var el = $(this).closest('.audio'),
        volume = el.find('.audio__volume').val() / 100;
        data = el.attr('data-audio');
        playing = el.hasClass('playing');
    !playing ? play(el, data, volume) : stop(el, data);
});

function play(el, data, volume) {
    audios[data].loop = true;
    audios[data].volume = volume;
    audios[data].play();
    el.addClass('playing');
}

function stop(el, data) {
    audios[data].pause();
    el.removeClass('playing');
}

function stopAll(el) {
    for(audio in audios) {
        audios[audio].pause();
        el.find('.audio').removeClass('playing');
    }
}

function checkIsVisible() {
    el = $('.audio-container');
    inicialPosElement = $('.audio-container').offset().top;
    finalPosElement = inicialPosElement + $('.audio-container').height();
    inicialPosScreen = $(window).scrollTop();
    finalPosScreen = inicialPosScreen + $(window).height();

    if(finalPosElement < inicialPosScreen || inicialPosElement > finalPosScreen) {
        stopAll(el);
    }
}

window.addEventListener('scroll', checkIsVisible);

});

...