如何在 Colorbox 中以幻灯片形式显示多个 div?

发布于 2024-11-08 01:33:40 字数 313 浏览 2 评论 0原文

假设我有一个由类 .eg '.myclass' 标识的 div 列表,

每个 div 内都会有一些 html 内容而不是图像。 我该如何打开 colorbox() 以便单击箭头时它们会快速浏览 div?

我查看了以下帖子,这是同样的问题,但他的解决方案没有给我任何关于他如何使其工作的线索: 重复问题

colorbox 是正确的插件吗?

Say I have a list of divs identified by class .e.g '.myclass'

Inside each div will be some html content rather than an image.
How do I go about opening the colorbox() so that on clicking the arrows, they will flick through the divs?

I looked at the following post which is the same problem, but his solution gives me no clue as to how he got it working: Duplicate question

Is colorbox even the correct plugin for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

余生一个溪 2024-11-15 01:33:40

更新:

我知道您已经接受了答案,但这里有一个比当前接受的答案更清晰的方法:

http://jsfiddle.net/rc5m7 /14/

HTML:

<div class="colorbox">Div #1
    <div style="display:none">
            Data#1 inside div.  This is just a test.
    </div>
</div>

<div class="colorbox">Div #2
    <div style="display:none">
            Data#2 inside div.  This is just a test.
    </div>
</div>

JS:

$(document).ready(function() {
    $('div.colorbox').each(function() {
        $(this).colorbox({
            html: $(this).find('div').html(),
            rel: 'group_1'
        });
    });
});

UPDATE:

I know you already accepted an answer, but here's a much cleaner approach than the currently accepted answer:

http://jsfiddle.net/rc5m7/14/

HTML:

<div class="colorbox">Div #1
    <div style="display:none">
            Data#1 inside div.  This is just a test.
    </div>
</div>

<div class="colorbox">Div #2
    <div style="display:none">
            Data#2 inside div.  This is just a test.
    </div>
</div>

JS:

$(document).ready(function() {
    $('div.colorbox').each(function() {
        $(this).colorbox({
            html: $(this).find('div').html(),
            rel: 'group_1'
        });
    });
});
毁梦 2024-11-15 01:33:40

这是我能得到的最好的。我必须将其与“rel”分组,并为您想要分组的每个 div 调用一次 colorBox。

http://jsfiddle.net/briguy37/rc5m7/

更新

我'已将上面的基本小提琴更新为 Adam 的解决方案。他很好地使用了 .each.find 来允许迭代相同 className 的 div,而不是通过唯一的 id。您可以在这里看到我的原始解决方案: http://jsfiddle.net/rc5m7/13/

Here's the best I could get it. I had to group it with 'rel', and call colorBox once for each div that you wanted to group.

http://jsfiddle.net/briguy37/rc5m7/

UPDATE

I've updated the base fiddle above to Adam's solution. He uses .each and .find nicely to allow iterating through divs of the same className rather than by unique id. You can see my original solution here: http://jsfiddle.net/rc5m7/13/

怪我鬧 2024-11-15 01:33:40

这对我来说非常有效 - 更喜欢将内联内容保留在一起。只需确保您使用最新的 Colorbox 版本(当前为 1.3.19)。

<a class="info_link" rel="help_msg1" href="#">Need help 1?</a>
<a class="info_link" rel="help_msg2" href="#">Need help 2?</a>

<div style="display: none;">
    <div id='help_msg1'>
        Help message 1 goes here
    </div>
    <div id='help_msg2'>
        Help message 2 goes here
    </div>
</div>

JS 看起来像这样:

$(document).ready(function() {
    $(".info_link").colorbox({    
      width:"50%",
      inline: true,
      href: function () { return '#'+$(this).attr('rel') }
    });
});

This worked for me perfectly - prefered to keep inline content all together. Just make sure you use the latest Colorbox version (currently 1.3.19).

<a class="info_link" rel="help_msg1" href="#">Need help 1?</a>
<a class="info_link" rel="help_msg2" href="#">Need help 2?</a>

<div style="display: none;">
    <div id='help_msg1'>
        Help message 1 goes here
    </div>
    <div id='help_msg2'>
        Help message 2 goes here
    </div>
</div>

And JS looks like that:

$(document).ready(function() {
    $(".info_link").colorbox({    
      width:"50%",
      inline: true,
      href: function () { return '#'+$(this).attr('rel') }
    });
});
梦年海沫深 2024-11-15 01:33:40

只是为了遵循 Adam 的解决方案,您实际上可以提供函数作为设置参数,这意味着您不必使用 有时会有点耗电的 each()

HTML:

<div class="colorbox">Div #1
    <div style="display:none">
            Data#1 inside div.  This is just a test.
    </div>
</div>

<div class="colorbox">Div #2
    <div style="display:none">
            Data#2 inside div.  This is just a test.
    </div>
</div>

JS:

$(document).ready(function() {
    $('div.colorbox').colorbox({
        html: function() { return $(this).find('div').html(); },
        rel: 'group_1'
    });
});

Just to follow on from Adam's solution, you can actually supply functions as settings parameters, which would mean you wouldn't have to use an each() which can sometimes be a little power hungry.

HTML:

<div class="colorbox">Div #1
    <div style="display:none">
            Data#1 inside div.  This is just a test.
    </div>
</div>

<div class="colorbox">Div #2
    <div style="display:none">
            Data#2 inside div.  This is just a test.
    </div>
</div>

JS:

$(document).ready(function() {
    $('div.colorbox').colorbox({
        html: function() { return $(this).find('div').html(); },
        rel: 'group_1'
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文