zoukankan      html  css  js  c++  java
  • bootstrap轮播图carousel插件

    一、基本介绍见:https://www.runoob.com/bootstrap/bootstrap-carousel-plugin.html

    二、例子:在PC端使用轮播图(高度固定,图片居中,容器铺满,使用背景图)

    复制代码
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- 指示器 -->
            <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>
            <!-- 轮播图片及说明文字 -->
            <div class="carousel-inner" role="listbox">
              <div class="item active">
                <a href="#" class="pc_imgBox" style="background-image: url('images/2-1.png')"></a>
              </div>
              <div class="item">
                <a href="#" class="pc_imgBox" style="background-image: url('images/2-2.png')"></a>
              </div>
              <div class="item">
                <a href="#" class="pc_imgBox" style="background-image: url('images/2-3.png')"></a>
              </div>
            </div>
            <!-- 控制按钮:左右切换 -->
            <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
              <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
              <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
          </div>
    复制代码
    复制代码
            .pc_imgBox{
                display: block;
                height: 400px;
                 100%;
                background-size: cover;
                background-position:  center;
                background-repeat: no-repeat;
            }
            .carousel-indicators{
                background: #ccc;
            }
     
    复制代码

    三、例子:在移动端使用轮播图(宽度自适应,高度自动变化,使用img引入图片)

    复制代码
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- 指示器 -->
            <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>
            <!-- 轮播图片及说明文字 -->
            <div class="carousel-inner" role="listbox">
              <div class="item active">
                <a href="#" class="pc_imgBox"><img src="images/1-1.png" alt=""></a>
              </div>
              <div class="item">
                <a href="#" class="m_imgBox"><img src="images/1-2.png" alt=""></a>
              </div>
              <div class="item">
                <a href="#" class="m_imgBox"><img src="images/1-3.png" alt=""></a>
              </div>
            </div>
            <!-- 控制按钮:左右切换 -->
            <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
              <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
              <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
          </div>
    复制代码
    复制代码
            .m_imgBox{
                display: block;
                 100%;
            }
            .carousel-indicators{
                background: #ccc;
            }
      
    复制代码

    四、例子:响应式的轮播图(利用媒体查询自适应PC端和移动端,注意应用在pc和移动端的图片是不一样的!)

    复制代码
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- 指示器 -->
            <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>
            <!-- 轮播图片及说明文字 -->
            <div class="carousel-inner" role="listbox">
              <div class="item active">
                <a href="#" class="pc_imgBox hidden-xs" style="background-image: url('images/2-1.png')"></a>
                <a href="#" class="m_imgBox hidden-lg hidden-md hidden-sm"><img src="images/1-1.png" alt=""></a>
              </div>
              <div class="item">
                <a href="#" class="pc_imgBox hidden-xs" style="background-image: url('images/2-2.png')"></a>
                <a href="#" class="m_imgBox hidden-lg hidden-md hidden-sm"><img src="images/1-2.png" alt=""></a>
              </div>
              <div class="item">
                <a href="#" class="pc_imgBox hidden-xs" style="background-image: url('images/2-3.png')"></a>
                <a href="#" class="m_imgBox hidden-lg hidden-md hidden-sm"><img src="images/1-3.png" alt=""></a>
              </div>
            </div>
            <!-- 控制按钮:左右切换 -->
            <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
              <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
              <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
          </div>
    复制代码
    复制代码
            .pc_imgBox{
                display: block;
                height: 400px;
                 100%;
                background-size: cover;
                background-position:  center;
                background-repeat: no-repeat;
            }
            .m_imgBox{
                display: block;
                 100%;
            }
            .carousel-indicators{
                background: #ccc;
            }
        
    复制代码
     

    ps:实现轮播图时间间隔改变的两种方式
    在data-ride后面加上一个属性data-interval=“millisecond”,其中,millisecond为需要设置的毫秒数,如下:
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="1000">
    使用JavaScript语句实现:
    官网给出的代码是:
    $('.carousel').carousel({
    interval: 2000
    });

  • 相关阅读:
    SSIS-SqlTask控件使用
    每年有20万人进军IT行业,为何人才缺口依旧这么大?
    推荐!5 本经典著作描绘C++学习路线图!
    C语言有了"链表"还用"数组"干嘛?因为你傻呀,怕你学不会!
    如何优化【if else】的面条代码,我们一起来解决代码复杂度问题!
    为什么要学编程一定要热爱?对不起我并不热爱编程,我只喜欢创造!
    程序员如何应对双十一的大数据冲击!是服务器先崩溃还是程序员先崩溃?
    【C语言项目】这21个入门练手项目,让你对C语言不再说难!
    【学习编程】有0.5倍速和2倍速的学习方法,那你看到过10倍速的学习技巧吗!
    外包程序员入职蚂蚁金服被质疑,网友评论人生污点,真就不拿外包当人了呗?
  • 原文地址:https://www.cnblogs.com/cui-ting/p/10837833.html
Copyright © 2011-2022 走看看