Jquery fadeout回调射击太快了

时间:2015-08-14 20:06:09

标签: javascript jquery jquery-callback

尽我所能我无法理解为什么这段代码...

function doVideoBanners () {

    // Set which banner we are fading out
    if ($('#youTubeBanner').length) {
        $theBannerToFade = $('#youTubeBanner');
    } else {
        $theBannerToFade = $('#revSliderBanner');
    }

    $('#find-h-banner-play').on('click', function() {

        // If code entry page, we don't need to scroll
        if (!$(this).hasClass('entry')) window.scrollTo(0, 0);

        $theBannerToFade.fadeOut('slow', function () {

            //////// Responsive YouTube iframe ////////
            var URL = 'xxxx';
            var videoIframe = '<iframe style="visibility:hidden;" onload="this.style.visibility=\'visible\'"; width="1100" height="524" class="youTube" src="http://www.youtube.com/embed/' + URL + '?rel=0;autoplay=1" frameborder="0" allowfullscreen allowtransparency></iframe>';

            // Because of elements jumping around, we need to set everything before we show the iframe
            $('.videoWrapper').html(videoIframe);

            // In the CSS videoWrapper is temporarily set to 524px
            $('.videoWrapper')
                .css('height', '0')
                .css('paddingBottom', '45.365%');

            $('.videoWrapper').removeClass('hidden');

        });

        // We don't want to restart the video should the user click it again
        $(this).off();
        $(this).css('cursor', 'default');

    });
}

...不会淡化元素然后触发回调。我试过.promise()和.done()。任何想法,还是专家?

1 个答案:

答案 0 :(得分:-1)

您是否尝试在功能上设置.delay()