Bootstrap 轮播直到悬停或单击才开始。行为无法在http://aagreen.dev.activemls.com查看
这是我的代码:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators"></ol>
<!-- Carousel items -->
<div class="carousel-inner"></div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
<script>
$(document).ready(function() {
$.getJSON("/property/slideshow_json").done(function(data){
//data is the array you expected.
showCarousel(data, 0);
})
function showCarousel(arr, index){
if(index >= arr.length) index = 0;
var item = arr[index];
//update the dom using the data item.mls_number, item.address, item.price
//$(".carousel-indicators").append($('<li data-target="#myCarousel" data-slide-to="' +index+ '"</li>'));
$(".carousel-inner").append($('<div class="item"><img src="/property/photo/'+item.mls_number+'/1"><div class="carousel-caption"><h4>PRICED TO SELL | $'+item.price+'</h4><p style="text-transform:uppercase;">'+item.address+' <a href="/property/detail/'+item.mls_number+'"class="btn btn-small btn-info pull-right">View Details</a></p></div></div>'));
//set the timer
setTimeout(function(){
showCarousel(arr, index+1);
}, 500);
}
$('#myCarousel').carousel({interval: 4000});
});
</script>
新代码:我试图简化我的代码,但仍然出现这种奇怪的行为,这似乎是 URL 特定的意思,例如 sandbox.dev.activemls.com 轮播加载正常,而在 aagreen.dev.activemls.com carousel 的行为与描述的一样,即:在悬停或单击之前不会激活。这是我的新脚本:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
<script>
$.getJSON("/property/slideshow_json", function(data){
$.each(data, function (index, value) {
console.log(index, value);
$(".carousel-indicators").append($( '<li data-target="#myCarousel" data-slide-to="' +index+ '"</li>' ));
$(".carousel-inner").append($('<div class="item"><img src="/property/photo/'+value.mls_number+'/1"><div class="carousel-caption"><h4>PRICED TO SELL | $'+value.price+'</h4><p style="text-transform:uppercase;">'+value.address+' <a href="/property/detail/'+value.mls_number+'"class="btn btn-small btn-info pull-right">View Details</a></p></div></div>'));
});
});
$('#myCarousel').carousel({interval: 4000});
</script>