【问题标题】:Is there a way to split (bootstrap) carousel content in 1 slide into 2 carousel slides dynamically?有没有办法将 1 张幻灯片中的(引导)轮播内容动态拆分为 2 张轮播幻灯片?
【发布时间】:2015-04-22 03:26:54
【问题描述】:

我目前正在使用 for 循环为 Twitter Bootstrap 的轮播渲染轮播幻灯片。对于每张幻灯片,内容也通过嵌套的 for 循环动态插入。我想要的是限制每张幻灯片中出现的项目数量(即 2 个项目)。如果还有更多,我想将它们移到下一张幻灯片中。

所以基本上,对于内部 for 循环中的每 2 个项目,创建一个新的轮播幻灯片,但要确保它是父轮播的一部分(而不是完全新的轮播)。

附上一张图片,希望能更好地说明我的观点。

我目前的代码(使用 PHP 框架 Laravel):

<div id="carousel-example-generic" class="carousel slide" data-interval="false">
    <div class="carousel-inner" role="listbox">
        @foreach ($carousel_slide) <!--rendering the carousel slide-->
        <div class="item">
            <div class="row">
                @foreach ($inner_content) <!--rendering the items in each slide-->
                <div class="col-md-6 col-xs-12">
                    <div class="inner-carousel-item">
                            {{{ $inner_content->image }}}
                        <span>{{{ $inner_content->caption }}}</span>
                    </div>
                </div>
                @endforeach
            </div>
         </div>
        @endforeach
    </div>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>

【问题讨论】:

    标签: php twitter-bootstrap laravel


    【解决方案1】:

    在这种情况下建议使用常规的for循环并不断增加索引。

    在内部循环中添加 2 个项目并每次递增计数器。这是这个的元代码

    for (;count($arr)>0;)
    build next carousel page
    for (;count($arr)>0;$item=array_pop($arr))
    build item on carousel page
    endfor
    endfor
    

    【讨论】:

    • .. 但这仅解决了内部循环,但不会在父轮播中为我呈现另一张幻灯片。
    • 处理两个循环。外循环不增加,jsut 检查数组中是否还有项目。内部循环递增计数器并将项目从数组中取出。
    • 对不起,我有点困惑。渲染轮播幻灯片的不是外循环吗?
      是每张幻灯片的 div。如果我要在内部循环中增加它(这是正确的),它在哪里“说”将额外的项目插入新的
      ?
    • 我添加了一个元代码示例来帮助澄清情况
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签