Jquery Content Carousel未正确加载项目

时间:2015-05-20 06:06:03

标签: jquery css asp.net-mvc twitter-bootstrap-3 carousel

我正在研究简单的bootstrap内容轮播.... Live Demo

问题是每个幻灯片应该加载3个项目.....从代码中可以看到但每个幻灯片上只加载一个项目....滑块的其余部分工作正常,除了项目加载...

剃刀代码:

<div class="container img-responsive" style="background: #d9e5e9;
padding-left: -0px; padding-bottom: 10px; padding-top: 10px;
margin: 20px auto; width: 980px;">
    <div class="carousel slide" id="myCarousel">
        <div class="carousel-inner">
            @{
                int counter = 0;
                foreach (var item in ViewBag.LoadEps)
                {
                    if (counter == 0)
                    {
                        <div class="item active">
                            <div class="col-lg-4">   
   <a href="@Url.Action("LoadEpisodes", "Home", new { id = item.VideoId,
    epId =item.VideoEpisodeId, name = item.Title.Replace(" ", "-")}, null)"
    style="color: white; text-align: center; line-height: 12px;">
    <img src="@Url.Content(item.PosterUrl)" height="130" 
    width="200" alt="@item.Title" class="ImageBorder" /><br />@item.Title
                                    </a>
                            </div>
                        </div>
                    }

                    else
                    {
                        <div class="item">
                            <div class="col-lg-4">

    <a href="@Url.Action("LoadEpisodes", "Home", new { id = item.VideoId,
    epId =item.VideoEpisodeId, name = item.Title.Replace(" ", "-")}, null)"
    style="color: white; text-align: center; line-height: 12px;">
    <img src="@Url.Content(item.PosterUrl)" height="130" 
    width="200" alt="@item.Title" class="ImageBorder" /><br />@item.Title
                                    </a>
                            </div>
                        </div>
                    }
                    counter++;
                }
            }
        </div>
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
        <i class="glyphicon glyphicon-chevron-left"></i></a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
        <i class="glyphicon glyphicon-chevron-right"></i></a>
    </div>
</div>

风格

<style>
    .carousel-inner .active.left {
        left: -25%;
    }

    .carousel-inner .next {
        left: 25%;
    }

    .carousel-inner .prev {
        left: -25%;
    }

    .carousel-control {
        width: 4%;
    }

        .carousel-control.left, .carousel-control.right {
            margin-left: 15px;
            background-color: #036ca6;
        }
</style>

脚本

<script>
    $(document).ready(function () {
        $('#myCarousel').carousel({
            interval: 4000
        })

        $('.carousel .item').each(function () {
            var next = $(this).next();
            if (!next.length) {
                next = $(this).siblings(':first');
            }
            next.children(':first-child').clone().appendTo($(this));

            for (var i = 0; i < 2; i++) {
                next = next.next();
                if (!next.length) {
                    next = $(this).siblings(':first');
                }

                next.children(':first-child').clone().appendTo($(this));
            }
        });
    });
</script>

只有加载项目的问题,虽然滑块工作正常,库加载正常.... 我不知道如何测试它并在firebug中发现错误,如控制台错误... 我自己也无法解决这个问题.... 如果有人请任何类型的帮助将不胜感激..... 谢谢你的时间..

1 个答案:

答案 0 :(得分:2)

这是一个OWL轮播的工作示例,它可以在我尝试过的任何地方正常工作,如果它不适合你,可以继续聊天,我会帮助你让它工作。

DEMO

<div id="owl-example" class="owl-carousel">
    <div> <img src="http://cdn.oxwordsblog.wpfuel.co.uk/wpcms/wp-content/uploads/Lion_iStock_XSmall-300x300.jpg?24a0bc" /> </div>
  <div> <img src="http://www.wildlife-pictures-online.com/image-files/lion-male_2724.jpg" /> </div>
  <div> <img src="http://upload.wikimedia.org/wikipedia/commons/9/94/Lion_Foret.jpg" /> </div>
    <div> <img src="http://cdn.oxwordsblog.wpfuel.co.uk/wpcms/wp-content/uploads/Lion_iStock_XSmall-300x300.jpg?24a0bc" /> </div>
  <div> <img src="http://www.wildlife-pictures-online.com/image-files/lion-male_2724.jpg" /> </div>
  <div> <img src="http://upload.wikimedia.org/wikipedia/commons/9/94/Lion_Foret.jpg" /> </div>
    <div> <img src="http://cdn.oxwordsblog.wpfuel.co.uk/wpcms/wp-content/uploads/Lion_iStock_XSmall-300x300.jpg?24a0bc" /> </div>
  <div> <img src="http://www.wildlife-pictures-online.com/image-files/lion-male_2724.jpg" /> </div>
  <div> <img src="http://upload.wikimedia.org/wikipedia/commons/9/94/Lion_Foret.jpg" /> </div>
</div>

$(document).ready(function() {
    $("#owl-example").owlCarousel({
        autoPlay: 3000, //Set AutoPlay to 3 seconds
        items : 3,   
    });
});