我试着添加它就像下一个按钮将有当前滑块加一和上一个按钮将有最后一个滑块id,这样它就可以回到那个滑块,但我被卡住了,就像我得到1+div前面id或-1 div后面id!!
@foreach($Topic->photos as $photo)
<?$pc++?>
<li id="no-js-slider-{{$pc}}" class="slide">
<img src="{{ URL::to('uploads/topics/'.$photo->file) }}">
<a class="prev" href="#no-js-slider-{{$pc}}">prev</a>
<a class="next" href="#no-js-slider-{{$pc++}}">next</a>
</li>
@endforeach
根据数组的外观,可以使用foreach获取索引。 然后使用索引计算下一个和上一个。 我认为这是一个更干净的方法。
@foreach($Topic->photos as $index => $photo)
//$index is the current iteration
<a class="prev" href="#no-js-slider-{{$index - 1}}">prev</a>
<a class="next" href="#no-js-slider-{{$index + 1)}}">next</a>
@endforeach
您必须在循环中调整它,但这取决于索引是第一张幻灯片还是最后一张幻灯片
//We're at the start
@if($index == 0)
@endif
//We've reached the end
@if($index == ($Topic->photos()->count() - 1))
@endif