一、轮播图组件模板(官方文档)

    <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">
<img src="..." alt="图片1">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="..." alt="图片2">
<div class="carousel-caption">
...
</div>
</div>
</div> <!-- 控制按钮:左右切换 -->
<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>

二、分析轮播图组件结构

①carousel 轮播图的模块, slide是否加上滑动效果,data-ride="carousel" 初始化轮播图属性

②data-target="#carousel-example-generic" 控制目标轮播图,data-slide-to="数字" 控制的是轮播图当中的第几张 (索引),class="active" 当前选中的点

③role="listbox" 提供给屏幕阅读器使用,class="carousel-inner"需要轮播的容器,每一个容器里class="item"包括轮播图片img和图片的说明性文字carousel-caption

④left carousel-control是切换上一张的按钮,right carousel-control是切换下一张的按钮,其中的data-slide="next/prev"声明左滑还是右滑,aria-hidden和sr-only是提供给屏幕阅读器使用

三、精简版轮播图模板

<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">
<img src="..." alt="图片1">
</div>
<div class="item">
<img src="..." alt="图片2">
</div>
<div class="item">
<img src="..." alt="图片3">
</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端使用轮播图(高度固定,图片居中,容器铺满,使用背景图)

<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;
width: 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="data:images/1-1.png" alt=""></a>
</div>
<div class="item">
<a href="#" class="m_imgBox"><img src="data:images/1-2.png" alt=""></a>
</div>
<div class="item">
<a href="#" class="m_imgBox"><img src="data: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;
width: 100%;
}
.carousel-indicators{
background: #ccc;
}

六、例子:响应式的轮播图(利用媒体查询自适应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="data: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="data: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="data: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;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.m_imgBox{
display: block;
width: 100%;
}
.carousel-indicators{
background: #ccc;
}

最新文章

  1. C#字符串的方法
  2. UDP传输
  3. QT 初阶 1.3 节 控件的几何排列
  4. -- c语言数据类型总结 --
  5. Android中取消GridView &amp; ListView默认的点击背景色
  6. linux系统的目录结构
  7. IOS中程序如何进行推送消息(本地推送,远程推送)2(上)
  8. 编辑并列DIV
  9. Epic - Spiral Matrix
  10. nginx总结
  11. Ajax+PHP简单入门教程
  12. LINQ动态查询类--[DynamicLinqExpressions]
  13. rageagainstthecage 源代码
  14. struts2 Session拦截器
  15. CodeForces 678B The Same Calendar
  16. html精确定位
  17. 浅谈MVC页面之间参数传递
  18. intellij安装lombok插件,解决注解@Slf4j注入后找不到变量log
  19. Haskell语言学习笔记(35)Contravariant
  20. docker及服务器遇到的坑

热门文章

  1. eclipse不提示问题
  2. C# 练习题 判断1至输入数值之间有多少个素数,并输出所有素数。
  3. k8s安装部署问题、解决方案汇总
  4. integer 面试题。
  5. 2019 新华网java面试笔试题 (含面试题解析)
  6. 在Windows中运行Linux bash命令的几种方法
  7. PHP CI框架调试开启报错信息方法
  8. Java 之 JSP
  9. ETL 的一些概念
  10. 【Code Tools】AB性能测试工具(二)