Bootstrap carousel multiple frames at once

前端 未结 14 1275
清酒与你
清酒与你 2020-11-22 07:51

This is the effect I\'m trying to achieve with Bootstrap 3 carousel

\"enter

In

14条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 08:10

    This is what worked for me. Very simple jQuery and CSS to make responsive carousel works independently of carousels on the same page. Highly customizable but basically a div with white-space nowrap containing a bunch of inline-block elements and put the last one at the beginning to move back or the first one to the end to move forward. Thank you insertAfter!

    $('.carosel-control-right').click(function() {
      $(this).blur();
      $(this).parent().find('.carosel-item').first().insertAfter($(this).parent().find('.carosel-item').last());
    });
    $('.carosel-control-left').click(function() {
      $(this).blur();
      $(this).parent().find('.carosel-item').last().insertBefore($(this).parent().find('.carosel-item').first());
    });
    @media (max-width: 300px) {
      .carosel-item {
        width: 100%;
      }
    }
    @media (min-width: 300px) {
      .carosel-item {
        width: 50%;
      }
    }
    @media (min-width: 500px) {
      .carosel-item {
        width: 33.333%;
      }
    }
    @media (min-width: 768px) {
      .carosel-item {
        width: 25%;
      }
    }
    .carosel {
      position: relative;
      background-color: #000;
    }
    .carosel-inner {
      white-space: nowrap;
      overflow: hidden;
      font-size: 0;
    }
    .carosel-item {
      display: inline-block;
    }
    .carosel-control {
      position: absolute;
      top: 50%;
      padding: 15px;
      box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.5);
      transform: translateY(-50%);
      border-radius: 50%;
      color: rgba(0, 0, 0, 0.5);
      font-size: 30px;
      display: inline-block;
    }
    .carosel-control-left {
      left: 15px;
    }
    .carosel-control-right {
      right: 15px;
    }
    .carosel-control:active,
    .carosel-control:hover {
      text-decoration: none;
      color: rgba(0, 0, 0, 0.8);
    }
    
    

提交回复
热议问题