发布于 2017-06-10 04:44:56 | 129 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Bootstrap入门,程序狗速度看过来!

Bootstrap Web前端CSS框架

Bootstrap是Twitter推出的一个开源的用于前端开发的工具包。它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架。Bootstrap提供了优雅的HTML和CSS规范,它即是由动态CSS语言Less写成。Bootstrap一经推出后颇受欢迎,一直是GitHub上的热门开源项目,包括NASA的MSNBC(微软全国广播公司)的Breaking News都使用了该项目。


这篇文章主要介绍了利用BootStrap的Carousel.js实现轮播图动画效果的相关资料,需要的朋友可以参考下

前期准备:

1.jquery.js。

2.bootstrap的carousel.js。

3.bootstrap.css。

一起来看代码吧:

页面比较丑,希望大家不要介意哦嘻嘻

效果图:

html+js:


<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>my love-首页</title>
 <link rel="stylesheet" href="css/bootstrap.css">
 <link rel="stylesheet" href="css/index.css">
 <link href="favicon.ico" rel="shortcut icon" />
 <script src="js/jquery.js" type="text/javascript"></script>
 <script src="js/carousel.js" type="text/javascript"></script>
</head>
<body>
 <div class="index-content">
  <div class="index-header">
   <nav class="navbar navbar-default">
    <div class="container-fluid">
     <div class="navbar-header">
      <a class="navbar-brand" href="javascript:void(0)">首页</a>
     </div>
     <div>
      <ul class="nav navbar-nav">
       <li class="active"><a href="#section1" class="con">向日葵花</a></li>
       <li><a href="#section2" class="con">萌萌哒的狗狗</a></li>
       <li><a href="#section3" class="con">好吃哒</a></li>
      </ul>
     </div>
    </div>
   </nav>
  </div>
  <div class="index-body">
   <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
     <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
     <li data-target="#carousel-example-generic" data-slide-to="1"></li>
     <li data-target="#carousel-example-generic" data-slide-to="2"></li>
    </ol>
    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
     <div class="item active">
      <img src="image/indexOne.jpg" alt="向日葵" class="images">
     </div>
     <div class="item">
      <img src="image/indexTwo.jpg" alt="萌萌哒狗狗" class="images">
     </div>
     <div class="item">
      <img src="image/indexThree.jpg" alt="好吃哒" class="images">
     </div>
    </div>
    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
     <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
     <span class="sr-only">Next</span>
    </a>
   </div>
  </div>
  <div class="index-footer">
   <div class="footer-centent">
    Copyright ©2016 爱喝酸奶的吃货
   </div>
  </div>
 </div>
 <script type="text/javascript">
  $(function() {
   $(".navbar-nav li").each(function(index) {
    $(this).click(function() {
     $("li.active").removeClass("active"); //注意这里
     $(this).addClass("active"); //注意这里
     $(".carousel-inner div.active").removeClass("active");
     $(".carousel-inner div").eq(index).addClass("active");
    });
   });
   window.setInterval(function() {
    $(".carousel-inner div").each(function(index) {
     if ($(this).hasClass("active")) {
      $(".navbar-nav li.active").removeClass("active");
      $(".navbar-nav li").eq(index).addClass("active");
     }
    });
   }, 100);
  });
 </script>
</body>
</html>

index.css


.container-fluid {
 padding-left: 200px;
}
.navbar-default {
 background-color: #308dca;
}
.navbar-brand {
 font-size: 34px;
 height: 70px;
}
.navbar-nav>li>a {
 font-size: 19px;
}
.navbar-default .navbar-brand, .navbar-default .navbar-nav>li>a, .navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus {
 color: #fff;
}
.navbar-brand, .navbar-nav>li>a {
 line-height: 40px;
}
.navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:hover, .navbar-default .navbar-nav>.active>a:focus {
 color: #fff;
 background-color: #2276bf;
}
.index-body {
 margin: 0 auto;
}
.carousel-inner {
 height: 490px;
}
.index-body, .images {
 width: 900px;
}
.index-footer {
 margin-top: 20px;
 color: #fff;
 background-color: #2276bf;
}
.footer-centent {
 width: 300px;
 font-size: 20px;
 line-height: 55px;
 margin: 0 auto;
 height: 60px;
}

大家在自己设计demo的时候注意下,class为index-body的div和img的宽度要设置一样,否则会出现以下情况:

以上所述是小编给大家介绍的利用BootStrap的Carousel.js实现轮播图动画效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对phperz网站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务