简体   繁体   English

Twitter Bootstrap Carousel Slide不起作用

[英]Twitter Bootstrap Carousel Slide Doesn't Work

I'm trying to implement Twitter Bootstrap Carousel plug in. It looks and auto cycles correctly, but the slide effect between items does not work. 我正在尝试实现Twitter Bootstrap Carousel插件。它看起来和自动循环正确,但项目之间的幻灯片效果不起作用。 It simply statically replaces one item with the next. 它简单地用下一个项目静态替换一个项目。 While it's functional, this is a less than pleasing UX. 虽然它功能齐全,但这是一个不太令人满意的用户体验。 Thoughts? 思考?

<div class="span7">
        <div id="myCarousel" class="carousel slide">
          <div class="carousel-inner">
            <div class="item active">
              <img src="img/CoachellaValley.png" alt="">
              <div class="carousel-caption">
                <h4>Sponsor 1</h4>
              </div>
            </div>
            <div class="item">
              <img src="img/CoachellaValley2.png" alt="">
              <div class="carousel-caption">
                <h4>Sponsor 2</h4>
              </div>
            </div>
            <div class="item">
              <img src="img/CoachellaValley3.png" alt="">
              <div class="carousel-caption">
                <h4>Sponsor 3</h4>
              </div>
            </div>
          </div>
          <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a>
          <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a>
        </div>
      </div>
[...]
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap-collapse.js"></script>
<script src="js/bootstrap-carousel.js"></script>
<script type="text/javascript">
  $(function(){
    $('#myCarousel').carousel();
  })
  </script>

Try this: 尝试这个:

Remove all the following js scripts you have loaded in your document: 删除您在文档中加载的所有以下js脚本:

<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-collapse.js"></script>
<script src="js/bootstrap-carousel.js"></script>

And just keep the following in that same order (jQuery goes first) 并按照相同的顺序保持以下内容(jQuery首先)

<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.js"></script>

The problem i believe is that, aside from loading the same script files multiple times (the bootstrap js file has all the plugins included already so no need to include the min version (save it for production for now) or the single separate script files), you're not loading the transition script included inside the bootstrap.js file because of the order that your scripts are loading in. 我相信的问题是,除了多次加载相同的脚本文件之外(bootstrap js文件已经包含了所有插件,所以不需要包含最小版本(现在保存它用于生产)或单个单独的脚本文件) ,您没有加载bootstrap.js文件中包含的转换脚本,因为脚本的加载顺序。

After struggling with this for a while I have found a solution - you just need to include 经过一段时间的努力,我找到了解决方案 - 你只需要包含

bootstrap-transition.js 引导-transition.js

and the slide animation will work. 幻灯片动画将起作用。

Deal is if I am using class="carousel" for carousel container and 交易是我使用class="carousel"用于轮播容器和

$('.carousel').carousel('slide',{interval:1000});

it works only for one left\\right click and works pretty much fine (but only for one time). 它仅适用于左/右键单击并且工作得很好(但只有一次)。

If use class="carousel slide" and 如果使用class="carousel slide"

$('.carousel .slide').carousel('slide',{interval:1000});

then carousel switching but without slide animation effect. 然后旋转木马切换但没有幻灯片动画效果。

Your Code is Correct.. In my system this code working fine.. 你的代码是正确的..在我的系统中这个代码工作正常..

There is no definition for class "slide" in Bootstrap 3..But without "Slide" class ,carousel images will change with out any animation effect.. Bootstrap 3中没有“幻灯片”类的定义。但是没有“幻灯片”类,轮播图像会随着任何动画效果而改变。

Add this script in you code 在您的代码中添加此脚本

<script>
    $(document).ready(function () {
        $('.carousel').carousel();
    });
</script>

Check the Bootstrap CSS & JS Reference in you code.. and also check the order of the Reference files 检查代码中的Bootstrap CSS&JS Reference,并检查Reference文件的顺序

You can follow this order:- 您可以按照以下顺序: -

  1. bootstrap.css bootstrap.css
  2. bootstrap-theme.css 自举theme.css
  3. jquery-1.9.1.js jQuery的1.9.1.js
  4. bootstrap.js bootstrap.js

The script block will not work with out JQ Library..So add JQ Library file correctly .. 脚本块不能用于JQ库..因此正确添加JQ库文件..

And Ensure that the JQ file loaded before the script working..For that you can add the reference at the top of your page 并确保在脚本工作之前加载JQ文件。为此,您可以在页面顶部添加引用

Even though this question was answered successfully - I came here looking for an answer to a similar problem. 尽管这个问题得到了成功解答 - 我来到这里寻找类似问题的答案。

My first item in the carousel was sliding left, like normal, but the second item wasn't behind it. 我在旋转木马上的第一个项目是向左滑动,就像正常一样,但第二个项目不在它后面。 Once the first item was off the screen, the second item would just appear, not slide in. Then it would disappear, and the first item would slide in properly. 一旦第一个项目离开屏幕,第二个项目就会出现,而不是滑入。然后它会消失,第一个项目将正确滑入。

If you're having this issue, check that you don't have position:relative; 如果您遇到此问题,请检查您是否有职位:亲属; on the .item div. 在.item div。

I added that like so: 我这样补充说:

.carousel-inner > .item {
    position:relative;
    height:495px;
}

Turns out that messes things up. 事实证明,这会让事情变得混乱。 Removing position:relative; 删除位置:相对; fixed the issue. 解决了这个问题。 Now sliding is smooth and correct. 现在滑动是顺畅和正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM