bootstrap和swiper的使用

迷南。 2022-06-08 07:50 620阅读 0赞

Bootstrap下载地址:http://www.bootcss.com/ (响应式框架)

Swiper 下载地址:http://www.swiper.com.cn/ (轮播框架)

一.引用:

//为了兼容手机端

  1. <!-- 如果要使用Bootstrap的JS插件,则必须引入jQuery -->
  2. <script src="js/jquery-2.2.3.min.js"></script>
  3. <!-- Bootstrap的JS插件 -->
  4. <script src="js/bootstrap.min.js"></script>
  5. <script src="js/jquery.unveilEffects.js"></script>
  6. <script src="js/swiper.animate1.0.2.min.js"></script>
  7. <script src="js/jquery.hovertreescroll.js"></script>
  8. <script src="js/swiper.min.js"></script>

注:1.引入js时必须先引入jquery 因为大部分控件都是基于jquery

  1. 2.如果需要更改框架原有样式,请把自己开发的css放在后边

二.bootstrap框架使用

开发文档见:http://v3.bootcss.com/

  1. bootstrap栅格将页面一行分为12格,高度为自适应,如需固定高度请自己设置css

    bootstrap根据不同尺寸设备将属性分为lg md xs sm四种 ,如果需要针对不同尺寸优化可以使用自带的样式,也可以通过media query进行自行修改如@media(max-width:@screen-xs-max){
    …}

  2. bootstrap可以设置不同尺寸设备的可见性,如visible-xs等

  3. bootstrap自带的头部导航为fixed的,即会跟随屏幕一直在顶端,但是需要设置

body{padding-top:导航高度+20px},否则导航下的控件会被覆盖显示不全

  1. 4. 如果需要居中容器可以设置:
  2. <divclass="container"> ... </div>但是宽度为70%
  3. 如需100%宽度请使用
  4. <divclass="container-fluid"> ... </div>
  5. 或者自己修改为width:100%
  6. 三. Swiper使用
  7. Swiper开发文档http://www.swiper.com.cn/api/index.html
  8. Swiper为跨平台的轮播框架,可以实现延迟动画等功能
  9. 1.使用swiper必须先初始化,多个控件可修改为.
  10. swiper-container1,.swiper-container2
  11. <script>
  12. $(document).ready(function () {
  13. var mySwiper = new Swiper('.swiper-container', {
  14. direction: 'horizontal',
  15. loop: true,
  16. autoplay: 3000,//可选选项,自动滑动
  17. autoplayDisableOnInteraction: false,
  18. grabCursor: true,
  19. speed: 300,
  20. // 如果需要分页器
  21. pagination: '.swiper-pagination',
  22. paginationType: 'bullets',
  23. paginationClickable: true,
  24. })
  25. }
  26. </script>

2.如果需要前进后退按钮可以添加

nextButton: ‘.swiper-button-next’,

prevButton:’.swiper-button-prev’,

其他控件见文档(如横屏竖屏滚动等)

3.基本内容为:

<divclass=”swiper-container”>

  1. <**div**class="swiper-wrapper">
  2. <**div**class="swiper-slide">Slide 1</**div**>
  3. <**div**class="swiper-slide">Slide 2</**div**>
  4. <**div**class="swiper-slide">Slide 3</**div**>
  5. </**div**>
  6. <!-- 如果需要分页器 \-->
  7. <**div**class="swiper-pagination"></**div**>
  8. <!-- 如果需要导航按钮 \-->
  9. <**div**class="swiper-button-prev"></**div**>
  10. <**div**class="swiper-button-next"></**div**>
  11. <!-- 如果需要滚动条 \-->
  12. <**div**class="swiper-scrollbar"></**div**>

</div>

5. 如果需要动画效果则需引入Swiper Animate

引入方式见一

引入后必须初始化,即在swiper初始方法中加入

  1. onInit: function (swiper) { //Swiper2.x的初始化是onFirstInit
  2. swiperAnimateCache(swiper); //隐藏动画元素
  3. swiperAnimate(swiper); //初始化完成开始动画
  4. }, onSlideChangeEnd: function (swiper) {
  5. swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
  6. }

之后只需需要动画效果中加入class=”ani”以及三个参数

<div class=”swiper-slide”>

内容

具体动画效果见:http://www.swiper.com.cn/usage/animate/index.html

6. 分页器和导航按钮样式可以通过修改swiper.css来改变,初始为背景色,可以修改为背景图

四开发中遇到的问题

1. li横向排布:float:left 浮动结束如果下个容器显示位置受到影响可以使用bootstrap提供的
或者

2. 容器左右居中:margin:0 auto; (0为margin-top 可以根据需求修改)

3. 文字上下居中:font-size:*;line-height:容器高度;

4. 文字左右居中:text-align: center

5. 微调容器位置 position: relative; top:?;bottom:?;left:?;right:?

6. Input中文字与左侧边框距离 padding-left:10px

7. 背景自动缩放到与容器大小一样 background:url(‘’) no-repeat; background-size:cover;

8. 背景自动拉伸到容器大小一样(完整显示一次)

9. background:url(‘’) no-repeat; background-size:contain;

10. css执行顺序:引入的从上到下,下面的会覆盖上面的,控件上的style优先级最高

11. 开发前,最好将样式清零:(使用bootstrap不需要,已经清除过了)

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,

abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,

var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{

margin: 0;

padding: 0;

border: 0;

outline: 0;

font-size: 100%;

vertical-align: baseline;

background: transparent;

}

发表评论

表情:
评论列表 (有 0 条评论,620人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Swiper-当中swiper嵌套

    这节课我们介绍swiper当中的swiper嵌套。   这次第一步有些不一样,虽然同样是要搭建swiper页面,但是我们在一个swiper页面当中的slide里面嵌套了

    相关 Swiper使用

    swiper是一个移动端的页面滑动框架,我们可以使用这个框架来编写自己的简历。 swiper当中除了页面滑动意外,还提供了其他各种各样的功能组件,供我们使用。