开发者

Lightbox not working after external loaded page with images

I have implemented lightbox-plugin for jQuery of krewenki in a masterpage including all images. This was working fine. Till i put the images in a external page and load this external images page in the master document. Lightbox does not work anymore. Is this jQuery code fault, or is this a lightbox-plugin problem?

Main-html

<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/jquery.lightbox.css" />
    <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
    <script src="js/jquery.lightbox.js" type="text/javascript"></script>
    <!-- http://github.com/krewenki/jquery-lightbox  -->
    <script language="JavaScript">
        jQuery(document).ready(function() {
            $("#loadimages").live('click', functi开发者_StackOverflow社区on() {
                $('#images').load('images.html');

                $(".lightbox").lightbox(); // THIS DOESN'T WORK???
            }       
        });
    </script>
</head>
<body>
    <div><a href="#" id="loadimages">Load images</a></div>
    <div id="images"></div>
</body>
</html>

images.html

<a href="image1.jpg" class="lightbox" rel="group1" title="image1"><img src="imgage1_thumb.jpg"/></a>
<a href="image2.jpg" class="lightbox" rel="group1" title="image2"><img src="imgage2_thumb.jpg"/></a>
<a href="image3.jpg" class="lightbox" rel="group2" title="image3"><img src="imgage3_thumb.jpg"/></a>
<a href="image4.jpg" class="lightbox" rel="group2" title="image4"><img src="imgage4_thumb.jpg"/></a>


You are not waiting for load() to finish before calling lightbox(). It is an asynchronous function, so you have to do it through a callback:

jQuery(document).ready(function() {
    $("#loadimages").live('click', function() {
        $('#images').load('images.html', function() {
            $(".lightbox").lightbox();
        });
    }       
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜