0

我正在尝试创建一个包含许多缩略图的页面,然后当您单击其中一个缩略图时,它会显示一个隐藏的图像颜色框。我已经尝试了几件事,我得到的最接近的显示在下面的代码中。问题是,一旦它到达一个缩略图下的一组图像的末尾,它就不会循环(我希望它循环)-而是移动到第二个缩略图下包含的下一组隐藏图像,依此类推。

感谢任何建议,如果代码到处都是,请随时告诉我。

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'/>
    <title>ColorBox Examples</title>
    <link rel="stylesheet" type="text/css" href="css/page.css">
    <link rel="stylesheet" href="colorbox.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7. /jquery.min.js"></script>
    <script src="../colorbox/jquery.colorbox.js"></script>
    <script>
        $(document).ready(function(){
            //Examples of how to assign the ColorBox event to elements
            $(".group1").colorbox({rel:'group1'});
            $(".group2").colorbox({rel:'group2', transition:"fade"});
            $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
            $(".group4").colorbox({rel:'group4', slideshow:true});
            $(".ajax").colorbox();
            $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
            $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
            $(".inline").colorbox({inline:true, width:"50%"});
            $(".callbacks").colorbox({
                onOpen:function(){ alert('onOpen: colorbox is about to open'); },
                onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
                onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
                onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
                onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
            });

            //Example of preserving a JavaScript event for inline calls.
            $("#click").click(function(){ 
                $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
                return false;
            });
        });
    </script>
</head>
<body>
            <div id = "imgHolder">
    <a class="group1" title="Photo1" href="../content/Largeimg1.jpg"><img alt="" src="../content/img1.jpg"></a>
    <a class="group1 hidden" title="Photo2" href="../content/Largeimg2.jpg"></a>
    <a class="group1 hidden" title="Photo3" href="../content/Largeimg3.jpg"></a>
    <a class="group1 hidden" title="Photo4" href="../content/Largeimg4.jpg"></a>
    <a class="group1 hidden" title="Photo5" href="../content/Largeimg5.jpg"></a>
    <a class="group1 hidden" title="Photo6" href="../content/Largeimg6.jpg"></a>
    <a class="group1" title="Photo7" href="../content/Largeimg2.jpg"><img alt="" src="../content/img2.jpg"></a>
    <a class="group1 hidden" title="Photo8" href="../content/Largeimg8.jpg"></a>
    <a class="group1 hidden" title="Photo9" href="../content/Largeimg9.jpg"></a>
    <a class="group1 hidden" title="Photo10" href="../content/Largeimg10.jpg"></a>
    <a class="group1 hidden" title="Photo11" href="../content/Largeimg11.jpg"></a>
    <a class="group1 hidden" title="Photo12" href="../content/Largeimg12.jpg"></a>
    <a class="group1" title="Photo13" href="../content/Largeimg3.jpg"><img alt="" src="../content/img3.jpg"></a>
    <a class="group1 hidden" title="Photo14" href="../content/Largeimg14.jpg"></a>
    <a class="group1 hidden" title="Photo15" href="../content/Largeimg15.jpg"></a>
    <a class="group1 hidden" title="Photo16" href="../content/Largeimg16.jpg"></a>
    <a class="group1 hidden" title="Photo17" href="../content/Largeimg17.jpg"></a>
    <a class="group1 hidden" title="Photo18" href="../content/Largeimg18.jpg"></a>
    <a class="group1" title="Photo19" href="../content/Largeimg4.jpg"><img alt="" src="../content/img4.jpg"></a>
    <a class="group1 hidden" title="Photo20" href="../content/Largeimg20.jpg"></a>
    <a class="group1 hidden" title="Photo21" href="../content/Largeimg21.jpg"></a>
    <a class="group1 hidden" title="Photo22" href="../content/Largeimg22.jpg"></a>
    <a class="group1 hidden" title="Photo23" href="../content/Largeimg23.jpg"></a>
    <a class="group1 hidden" title="Photo24" href="../content/Largeimg24.jpg"></a>
    </div>

</body>
</html>
4

2 回答 2

0

提供与属性rel相同的data-group属性。

$(".photo").colorbox({ rel: $(this).data('group') });
于 2013-04-27T13:59:19.790 回答
0

您需要一些东西来表明您希望这些链接如何组合在一起。这是一种方法的示例:

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'/>
    <title>ColorBox Examples</title>
    <link rel="stylesheet" type="text/css" href="css/page.css">
    <link rel="stylesheet" href="colorbox.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7. /jquery.min.js"></script>
    <script src="../colorbox/jquery.colorbox.js"></script>
    <script>
        $(document).ready(function(){
            $(".photo").colorbox({rel:function(){
                return $(this).attr('data-group');
            }});
        });
    </script>
</head>
<body>
    <div id = "imgHolder">
    <a data-group='1' class="photo" title="Photo1" href="../content/Largeimg1.jpg"><img alt="" src="../content/img1.jpg"></a>
    <a data-group='1' class="photo hidden" title="Photo2" href="../content/Largeimg2.jpg"></a>
    <a data-group='1' class="photo hidden" title="Photo3" href="../content/Largeimg3.jpg"></a>
    <a data-group='1' class="photo hidden" title="Photo4" href="../content/Largeimg4.jpg"></a>
    <a data-group='1' class="photo hidden" title="Photo5" href="../content/Largeimg5.jpg"></a>
    <a data-group='1' class="photo hidden" title="Photo6" href="../content/Largeimg6.jpg"></a>
    <a data-group='2' class="photo" title="Photo7" href="../content/Largeimg2.jpg"><img alt="" src="../content/img2.jpg"></a>
    <a data-group='2' class="photo hidden" title="Photo8" href="../content/Largeimg8.jpg"></a>
    <a data-group='2' class="photo hidden" title="Photo9" href="../content/Largeimg9.jpg"></a>
    <a data-group='2' class="photo hidden" title="Photo10" href="../content/Largeimg10.jpg"></a>
    <a data-group='2' class="photo hidden" title="Photo11" href="../content/Largeimg11.jpg"></a>
    <a data-group='2' class="photo hidden" title="Photo12" href="../content/Largeimg12.jpg"></a>
    <a data-group='3' class="photo" title="Photo13" href="../content/Largeimg3.jpg"><img alt="" src="../content/img3.jpg"></a>
    <a data-group='3' class="photo hidden" title="Photo14" href="../content/Largeimg14.jpg"></a>
    <a data-group='3' class="photo hidden" title="Photo15" href="../content/Largeimg15.jpg"></a>
    <a data-group='3' class="photo hidden" title="Photo16" href="../content/Largeimg16.jpg"></a>
    <a data-group='3' class="photo hidden" title="Photo17" href="../content/Largeimg17.jpg"></a>
    <a data-group='3' class="photo hidden" title="Photo18" href="../content/Largeimg18.jpg"></a>
    <a data-group='4' class="photo" title="Photo19" href="../content/Largeimg4.jpg"><img alt="" src="../content/img4.jpg"></a>
    <a data-group='4' class="photo hidden" title="Photo20" href="../content/Largeimg20.jpg"></a>
    <a data-group='4' class="photo hidden" title="Photo21" href="../content/Largeimg21.jpg"></a>
    <a data-group='4' class="photo hidden" title="Photo22" href="../content/Largeimg22.jpg"></a>
    <a data-group='4' class="photo hidden" title="Photo23" href="../content/Largeimg23.jpg"></a>
    <a data-group='4' class="photo hidden" title="Photo24" href="../content/Largeimg24.jpg"></a>
    </div>
</body>
</html>
于 2012-07-30T07:02:29.170 回答