【问题标题】:Asp.net bootstrap carousel slider does not workAsp.net 引导轮播滑块不起作用
【发布时间】:2015-06-19 19:51:09
【问题描述】:

我一直在尝试遵循教程并实现引导轮播滑块。我想稍后在我自己的网页中使用它,但我只是想让它工作。

现在它没有在我在 Visual Studio 中创建的 asp.net 网络表单中显示任何内容。我不确定是什么问题,因为代码是一样的。

代码:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Fullslider</title>

     <link href="Content/full-slider.css" rel="stylesheet" />
    <link href="Content/bootstrap.min.css" rel="stylesheet" />


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


</head>
<body>
<form id="form1" runat="server">

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Start Bootstrap</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#">About</a>
                    </li>
                    <li>
                        <a href="#">Services</a>
                    </li>
                    <li>
                        <a href="#">Contact</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    <!-- Full Page Image Background Carousel Header -->
    <header id="myCarousel" class="carousel slide" data-ride="carousel">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1"></li>
            <li data-target="#myCarousel" data-slide-to="2"></li>
        </ol>

        <!-- Wrapper for Slides -->
        <div class="carousel-inner">
            <div class="item active">
                <!-- Set the first background image using inline CSS below. -->
                <div class="fill" style="background-image: url('http://placehold.it/1900x1080&text=Slide One');"></div>
                <div class="carousel-caption">
                </div>
            </div>
            <div class="item">
                <!-- Set the second background image using inline CSS below. -->
                <div class="fill" style="background-image: url('http://placehold.it/1900x1080&text=Slide Two');"></div>
                <div class="carousel-caption">
                </div>
            </div>
            <div class="item">
                <!-- Set the third background image using inline CSS below. -->
                <div class="fill" style="background-image: url('http://placehold.it/1900x1080&text=Slide Three');"></div>
                <div class="carousel-caption">
                    <h2>Caption 3</h2>
                </div>
            </div>
        </div>

        <!-- Controls -->
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
            <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
            <span class="icon-next"></span>
        </a>

    </header>

           <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Script to Activate the Carousel -->
    <script>
        $('.carousel').carousel({
            interval: 5000 //changes the speed
        })
</script>

</form>


</body>
</html>

代码有标准的引导导航栏,效果很好。但轮播应该是空白的。

大家能看出哪里不对吗?

CSS 文件:

/*!
 * Start Bootstrap - Full Slider HTML Template (http://startbootstrap.com)
 * Code licensed under the Apache License v2.0.
 * For details, see http://www.apache.org/licenses/LICENSE-2.0.
 */

html,
body {
    height: 100%;
}

.carousel,
.item,
.active {
    height: 100%;
}

.carousel-inner {
    height: 100%;
}

/* Background images are set within the HTML using inline CSS, not here */

.fill {
    width: 100%;
    height: 100%;
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
}

footer {
    margin: 50px 0;
}

【问题讨论】:

  • 为什么你把jquery.jsbootstrap.min.js加了两次?
  • 我还很新.. 所以这只是我试图让它发挥作用的东西
  • 你想要整页滑块??我的意思是显示为身体背景的幻灯片??
  • 这只是我遵循的教程.. 我只是希望它能够工作,因为这样我就可以自己完成剩下的工作了.. 但看不出有什么问题,我没有那么有经验.

标签: css asp.net twitter-bootstrap


【解决方案1】:

好的,我刚刚看到一些不同的代码可能是因为它可能不起作用!

以下是可能导致它不起作用的原因:

  • 您使用的是 &lt;header&gt; 而不是 div
  • 基本上您使用的是 &lt;div&gt; 而不是 &lt;img&gt; 并且您曾经设置 @ &lt;div&gt; 中的 987654326@ 和 caption 您还有一个 div。李>
  • 您在 &lt;div&gt; 中添加了一些额外的类,这些类有自己的样式,会影响其原始样式
  • 总体上它在后台工作,但它的高度受到影响

看看这个 DEMO 带有轮播的基本和初始设计

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
      <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1"></li>
            <li data-target="#myCarousel" data-slide-to="2"></li>
            <li data-target="#myCarousel" data-slide-to="3"></li>
      </ol>

      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
            <div class="item active">
                <img src="https://placehold.it/1900x1080&text=Slide One" alt="Chania"/>
            </div>

            <div class="item">
                <img src="https://placehold.it/1900x1080&text=Slide Two" alt="Chania"/>
            </div>

            <div class="item">
                <img src="https://placehold.it/1900x1080&text=Slide Three" alt="Flower"/>
            </div>

            <div class="item">
                <img src="https://placehold.it/1900x1080&text=Slide Two" alt="Flower"/>
            </div>
      </div>

  <!-- Left and right controls -->
      <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
      </a>
 </div>

【讨论】:

  • 谢谢,对我来说,问题是将 div 更改为图像,例如:。 @Guruprasad Rao
  • @zahed.. 很高兴它有帮助.. 编码愉快.. :)
猜你喜欢
  • 2016-11-27
  • 2015-04-16
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
  • 2020-10-06
  • 2021-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多