bootstrap之carousel

一、前言

这节介绍下carousel(轮播)模块的源码实现。

二、源码

1、carousel.less
 //
 // Carousel(图片轮播)
 // --------------------------------------------------

 // Wrapper for the slide container and indicators(轮播图容器)
 .carousel {
   position: relative;
 }

 // 轮播图片播放区
 .carousel-inner {
   position: relative;
   overflow: hidden;
   width: 100%;

   > .item {
     display: none;
     position: relative;
     .transition(.6s ease-in-out left);

     // Account for jankitude on images
     > img,
     > a > img {
       &:extend(.img-responsive);
       line-height: 1;
     }

     // WebKit CSS3 transforms for supported devices
     @media all and (transform-3d), (-webkit-transform-3d) {
       .transition-transform(~'0.6s ease-in-out');
       .backface-visibility(~'hidden');
       .perspective(1000px);

       &.next,
       &.active.right {
         .translate3d(100%, 0, 0);
         left: 0;
       }
       &.prev,
       &.active.left {
         .translate3d(-100%, 0, 0);
         left: 0;
       }
       &.next.left,
       &.prev.right,
       &.active {
         .translate3d(0, 0, 0);
         left: 0;
       }
     }
   }

   > .active,
   > .next,
   > .prev {
     display: block;
   }

   > .active {
     left: 0;
   }

   > .next,
   > .prev {
     position: absolute;
     top: 0;
     width: 100%;
   }

   > .next {
     left: 100%;
   }
   > .prev {
     left: -100%;
   }
   > .next.left,
   > .prev.right {
     left: 0;
   }

   > .active.left {
     left: -100%;
   }
   > .active.right {
     left: 100%;
   }

 }

 // Left/right controls for nav(轮播图片控制器)
 // ---------------------------
 .carousel-control {
   position: absolute;
   top: 0;
   left: 0;
   bottom: 0;
   width: @carousel-control-width;
   .opacity(@carousel-control-opacity);
   font-size: @carousel-control-font-size;
   color: @carousel-control-color;
   text-align: center;
   text-shadow: @carousel-text-shadow;
   background-color: rgba(0, 0, 0, 0); // Fix IE9 click-thru bug
   // We can't have this transition here because WebKit cancels the carousel
   // animation if you trip this while in the middle of another animation.

   // Set gradients for backgrounds
   &.left {
     #gradient > .horizontal(@start-color: rgba(0,0,0,.5); @end-color: rgba(0,0,0,.0001));
   }
   &.right {
     left: auto;
     right: 0;
     #gradient > .horizontal(@start-color: rgba(0,0,0,.0001); @end-color: rgba(0,0,0,.5));
   }

   // Hover/focus state
   &:hover,
   &:focus {
     outline: 0;
     color: @carousel-control-color;
     text-decoration: none;
     .opacity(.9);
   }

   // Toggles
   .icon-prev,
   .icon-next,
   .glyphicon-chevron-left,
   .glyphicon-chevron-right {
     position: absolute;
     top: 50%;
     margin-top: -10px;
     z-index: 5;
     display: inline-block;
   }
   .icon-prev,
   .glyphicon-chevron-left {
     left: 50%;
     margin-left: -10px;
   }
   .icon-next,
   .glyphicon-chevron-right {
     right: 50%;
     margin-right: 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值