加载图像后使div可见

时间:2013-08-14 15:59:55

标签: jquery css html load visible

在我的网站上,我在div中有一个SWF,它覆盖了我的logo png图像。我希望这个包含SWF的div仅在使用jQuery加载徽标图像后出现。

overlay.php包含SWF代码

<div id="overlay"><?php include "overlay.php"?></div>
<div id="logo"></div>

jQuery的:

  <script type="text/javascript">
    $('#header').on('load',function(){
        $('#overlay').css("visibility","visible");
    });
    </script>

的CSS:

#overlay{
    position:absolute;  
    z-index:2; 
    visibility:hidden;
}

#header{
    background-image:url(logo.png); 
    background-repeat:no-repeat;
    position:relative;
    z-index:1; 
}

1 个答案:

答案 0 :(得分:2)

您可以添加一个侦听图像加载的事件:

$('img').on('load',function(){
    $('#overlay').show();
});

当然,您需要先隐藏div并将img更改为相应的idclass。与div相同。

如果您的图片是background-image,可以试试这个:

$('<img>').attr('src',function(){
    var imgUrl = $('#header').css('background-image');
    imgUrl = imgUrl.substring(4, imgUrl.length-1);
    return imgUrl;
}).load(function(){
    $('#overlay').show();
});