我在实施bootstrap轮播时遇到问题。任何人都可以看看下面的html和js,并给我如何实现幻灯片的说明。 .js尚未编辑,旋转木马安装在正文英雄单元上。我是否实施了旋转木马api?如何在.js文件中定义我正在使用的轮播?谢谢。
<div class="carousel">
<!-- Carousel items -->
<div class="carousel-inner">
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-large">Learn more »</a></p>
</div>
</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>
答案 0 :(得分:8)
注意:此答案最初用于 Bootstrap 2.3.2 (可能不适用于版本3)
您必须在所有幻灯片上放置“item”类,并在第一张幻灯片上将该类设置为“active”。这对我有用。
<div class="carousel">
<div class="carousel-inner">
<!-- your slide -->
<div class="hero-unit item active">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-large">Learn more »</a></p>
</div>
</div>
</div>
和克里斯托弗一样,你需要使用这个功能来启动它。
<script type="text/javascript">
$(function(){
$('.carousel').carousel();
});
</script>
答案 1 :(得分:6)
我的理解是
<div class="carousel">
需要
<div id="myCarousel" class="carousel">
其中id是“箭头”'href的任何内容。
答案 2 :(得分:3)
Bootstrap Carousel的文档可在此处找到:http://twitter.github.com/bootstrap/javascript.html#carousel
我想你需要添加类似的内容才能让它运行:
<script type="text/javascript">
$(function(){
$('.carousel').carousel();
});
</script>
答案 3 :(得分:1)
您的示例代码中没有任何项目。 为了让它工作,你需要至少有两个项目,在你的轮播内部div。
<div class="carousel-inner">
<div class="active item">…</div>
<div class="item">…</div>
<div class="item">…</div>
</div>
答案 4 :(得分:0)
这是在Joomla 3.1.1中使用基于Bootstrap的Protostar模板。 我没有让旋转木马自动循环。这对我有用:
使用自定义html模块,添加以下代码:
(更改img
scr
,替换文字和字幕文字以进行自定义)
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators" style="list-style: none;">
<li class="active" data-target="#myCarousel" data-slide-to="0"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<img src="images/headers/maple.jpg" alt="imagetext 1" />
<div class="carousel-caption">
<h4>Exampletext 1</h4>
</div>
</div>
<div class="item">
<img src="images/headers/raindrops.jpg" alt="imagetext 2" />
<div class="carousel-caption">
<h4>Exampletext</h4>
</div>
</div>
<div class="item">
<img src="images/headers/windows.jpg" alt="imagetext 3" />
<div class="carousel-caption">
<h4>Exampletext</h4>
</div>
</div>
</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>
<!-- Call Carousel -->
<script type="text/javascript">
(function($){$('.carousel').carousel({ interval: 5000, pause:'hover'});
})(jQuery);
</script>
模板的index.php中的这种调整是为了防止脚本之间的混淆,它会禁用mootools,这会导致轮播在幻灯片之间打开和关闭:
// CSUTOM disable mootools-more.js
unset (JFactory::getDocument()->_scripts['/jomaatcms/media/system/js/mootools-core.js']);
unset (JFactory::getDocument()->_scripts['/jomaatcms/media/system/js/mootools-more.js']);