实现 twitter bootstrap carousel v2.3.2

发布于 2025-01-03 19:00:58 字数 1046 浏览 1 评论 0原文

我在实现引导轮播时遇到问题。谁能看一下下面的 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 &raquo;</a></p>
      </div>  

  </div>      

 <!-- Carousel nav -->

  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>

  </div>

I am having trouble implementing the bootstrap carousel. Can anyone look at the following html and js and give me instructions on how to implement the slide. The .js has not been edited and the carousel is installed on the body hero unit. Do I implement the carousel api? How do I define the carousel I am using within the .js file? Thanks.

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

各空 2025-01-10 19:00:59

我的理解是,

<div class="carousel">

都需要位于id 的位置。

<div id="myCarousel" class="carousel">

无论“箭头”的 href 是什么,

My understanding is that

<div class="carousel">

Needs to be

<div id="myCarousel" class="carousel">

where the id is whatever the "Arrows"' href is.

┼── 2025-01-10 19:00:59

Bootstrap Carousel 的文档可在此处找到: http://twitter.github.com/bootstrap/ javascript.html#carousel

我想您需要添加类似的内容才能使其运行:

<script type="text/javascript">
$(function(){
   $('.carousel').carousel();
});
</script>

The documentation for Bootstrap Carousel is available here: http://twitter.github.com/bootstrap/javascript.html#carousel

I guess you would need to add something like this to get it running:

<script type="text/javascript">
$(function(){
   $('.carousel').carousel();
});
</script>
你怎么敢 2025-01-10 19:00:59

您的示例代码中没有任何项目。
为了让它工作,你需要至少有两个项目,在你的 carousel-inner div 中。

  1. 创建第二个项目,
  2. 确保第一个项目具有活动类;这开始了,
  3. 裸代码应该看起来像这样

<div class="carousel-inner">
   <div class="active item">…</div>
   <div class="item">…</div>
   <div class="item">…</div>
</div>

You have no items in your example code.
to get it to work you need to have at least two items, with in your carousel-inner div.

  1. create a second item
  2. make sure the first item has the active class; this starts the ball rolling
  3. the bare code should look like this

.

<div class="carousel-inner">
   <div class="active item">…</div>
   <div class="item">…</div>
   <div class="item">…</div>
</div>
淡水深流 2025-01-10 19:00:59

这是 Joomla 3.1.1 中的 Protostar 模板,该模板基于 Bootstrap。
我没有让旋转木马自动循环。这对我有用:

使用自定义 html 模块,添加以下代码:
(更改 img scr、alt 文本和标题文本以进行自定义)

<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']);

This is in Joomla 3.1.1 with the Protostar template which is based on Bootstrap.
I did't get the carousel to automticly cycle. This worked for me:

Use a Custom html module, add this code:
(change the img scr, alt text and caption text to customize)

<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>

This adjustments in the index.php of your template is to prevent confict between scripts, it disables mootools which causes the carousel to open and close beween slides:

// 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']);
小猫一只 2025-01-10 19:00:58

注意:此答案最初适用于Bootstrap 2.3.2< /strong>(可能不适用于版本 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>

Note: this answer was originally for Bootstrap 2.3.2 (may not work with version 3)

You have to put the class "item" on all of your slides and the class "active" on the first slide. This worked for me.

<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>

And like Christopher said you need to use this function to initiate it.

<script type="text/javascript">
$(function(){
   $('.carousel').carousel();
});
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文