【发布时间】:2014-12-31 21:52:56
【问题描述】:
我有一个使用引导轮播的网站。这是我的代码:
<div id="slider">
<div id="carousel-bounding-box">
<div class="carousel slide" id="myCarousel">
<div class="carousel-inner">
<?php
if ($images = get_field('images', $design_id)) {
foreach ($images as $key => $image) {
$active = $key == 0 ? 'active' : '';
echo 'item" data-interval="1000">';
echo '<img src="' . $image['image']['sizes']['large'] . '" />';
echo '</div>'; }
}
?>
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
这是我的 jQuery:
jQuery(document).ready(function($) {
$('#myCarousel').carousel({
interval: 1000
});
$('#carousel-text').html($('#slide-content-0').html());
//Handles the carousel thumbnails
$('[id^=carousel-selector-]').click( function(){
var id_selector = $(this).attr("id");
var id = id_selector.substr(id_selector.length -1);
var id = parseInt(id);
$('#myCarousel').carousel(id);
});
// When the carousel slides, auto update the text
$('#myCarousel').on('slid.bs.carousel', function (e) {
var id = $('.item.active').data('slide-number');
$('#carousel-text').html($('#slide-content-'+id).html());
});
(function($) {
fakewaffle.responsiveTabs(['xs', 'sm']);
});
});
我将间隔:5000 更改为间隔:1000,因为在页面加载时滑块显示项目存在延迟。由于将间隔更改为 1000,滑块可以完美且快速地加载,但是现在需要放慢幻灯片项目的速度,因为它们在幻灯片之间太快了。
我认为问题在于直到间隔之后才将“活动”状态赋予幻灯片/图像。如何在页面加载时自动为第一个幻灯片项的上述代码添加活动状态,而不是等到间隔之后?
任何帮助将不胜感激
【问题讨论】:
-
你不能在echo里面使用echo,看起来是php错误。
-
感谢指出,会更正:-)
-
如何改回它并使用窗口加载而不是文档准备好:4loc.wordpress.com/2009/04/28/documentready-vs-windowload -- 你可以试试。
-
基本上看到那个item:first 这就是你需要的,你需要再做一个,就在下面使用类似语法的li 的:first。试一试,等我回来再看看
标签: javascript php jquery twitter-bootstrap