代码之家  ›  专栏  ›  技术社区  ›  waqmaz

使用jQuery attr div将GIF加载到div

  •  0
  • waqmaz  · 技术社区  · 11 年前
        $('#captcha').attr('src', 'captcha.php?' + (new Date()).getTime());
    });
    </script>
    

    它工作得很好 img 具有 id=captcha 正在隐藏,但取消注释时加载的GIF不想显示 load('#loading') 或者写一些类似的东西。有什么建议吗?

    1 回复  |  直到 11 年前
        1
  •  1
  •   A. Wolff    11 年前

    您应该尝试以下代码:

    $('#reload').click(function () {
        if ($(this).data('isLoading')) return;
        $(this).data('isLoading', true);
        var $container = $('#captcha').parent(),
            $loading = $('<div id="loading"/>');
        $('#captcha').hide(0, function () {
            $loading.prependTo($container)
        }).one('load', function () {
             $('#loading').remove();
            $(this).fadeIn(400, function () {           
                $('#reload').data('isLoading', false);
            });
        }).attr('src', 'captcha.php?' + $.now());
    });
    

    并使用以下CSS:

    #loading {
        float: left; /* <<< add this one */
        background: transparent url(obrazki/reload.gif) no-repeat center center; /* use transparent color, you btw should modificate img to fit with height */
        width: 80px;
        height: 35px;
    }