首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何循环旋转?

如何循环旋转?
EN

Stack Overflow用户
提问于 2020-12-08 10:36:02
回答 3查看 73关注 0票数 0

我试图用类“活动”第一项来循环传送带。

这是我的密码

代码语言:javascript
复制
<div class="carousel-item active">
    <div class="top-top">
        <h4>some heading</h4>
        <iframe class="testimonial" width="100%" height="auto"
                src="https://www.youtube.com/embed/ynK2WIRg?rel=0" frameborder="0"
                allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
        </iframe>
    </div>
</div>

@foreach($test as $tes)
<div class="carousel-item">
    <div class="top-top">
        <h4>{{ $tes->name }}</h4>
        <iframe class="testimonial" width="100%" height="auto"
                src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0"
                allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
        </iframe>
    </div>
</div>
@endforeach
</div>

我也试图将活动项放在循环中。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-12-08 10:41:14

您可以使用$loop->iteration==1,如在foreach中的laravel刀片医生中所说:

代码语言:javascript
复制
@foreach($test as $tes)
    <div class="carousel-item @if($loop->iteration==1) active @endif">
        <div class="top-top">
        <h4>{{ $tes->name }}</h4>
        <iframe class="testimonial" width="100%" height="auto"
            src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
        </iframe>
        </div>
    </div>
@endforeach
票数 0
EN

Stack Overflow用户

发布于 2020-12-08 10:43:27

您可以在循环中使用回路变量

代码语言:javascript
复制
@foreach($test as $tes)
<div class="carousel-item@if($loop->first) active@endif">
    <div class="top-top">
        <h4>{{ $tes->name }}</h4>
        <iframe class="testimonial" width="100%" height="auto"
            src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
        </iframe>
    </div>
</div>
@endforeach
票数 0
EN

Stack Overflow用户

发布于 2020-12-08 10:47:06

您可以使用循环变量

在您的循环中,您可以访问许多有用的信息,例如如果是第一个或最后一个循环,当前循环计数,如果偶数或奇数.在这里,您可以在官方文档中找到所有的信息。

https://laravel.com/docs/8.x/blade#the-loop-variable

在你的例子中,你可以这样做:

代码语言:javascript
复制
@foreach($test as $tes)
    @if ($loop->first)
    <div class="carousel-item active">
        <div class="top-top">
            <h4>{{ $tes->name }}</h4>
            <iframe class="testimonial" width="100%" height="auto"
                    src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0"
                    allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
            </iframe>
        </div>
    </div>
    @else
    <div class="carousel-item">
        <div class="top-top">
            <h4>{{ $tes->name }}</h4>
            <iframe class="testimonial" width="100%" height="auto"
                    src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0"
                    allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="">
            </iframe>
        </div>
    </div>
    @endif
@endforeach
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65197302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档