"Bootstrap Multi Items Responsive Carousel and Modal"
Bootstrap 4.1.1 Snippet by Monoxa

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div id="carouselPlus" class="carousel slide multi-carousel" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=1-1" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=1-1" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=1-2" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=1-2" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=1-3" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=1-3" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=1-4" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=1-4" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=2-1" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=2-1" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=2-2" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=2-2" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=2-3" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=2-3" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=2-4" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=2-4" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=3-1" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=3-1" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=3-2" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=3-2" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=3-3" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=3-3" alt="First slide"></a></div> <div class="carousel-grid col-lg-3 col-md-4 col-sm-12"><a href="#" data-image="https://dummyimage.com/1280x1024/000000/fff.png&text=3-4" data-toggle="modal" data-target="#modal" class="w-100" alt=""><img class="d-block w-100" src="https://dummyimage.com/720x480/000/fff.png&text=3-4" alt="First slide"></a></div> </div> <a class="carousel-control-prev" href="#carouselPlus" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselPlus" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> </div> <!-- Modal --> <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="Lightbox Gallery by Bootstrap 4" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-body"> <div id="lightbox" class="carousel slide" data-ride="carousel" data-interval="5000" data-keyboard="true"> <ol class="carousel-indicators"> <li data-target="#lightbox" data-slide-to="0"></li> <li data-target="#lightbox" data-slide-to="1"></li> <li data-target="#lightbox" data-slide-to="2"></li> <li data-target="#lightbox" data-slide-to="3"></li> <li data-target="#lightbox" data-slide-to="4"></li> <li data-target="#lightbox" data-slide-to="5"></li> <li data-target="#lightbox" data-slide-to="6"></li> <li data-target="#lightbox" data-slide-to="7"></li> </ol> <div class="carousel-inner"> </div> <a class="carousel-control-prev" href="#lightbox" role="button" data-slide="prev"><span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="sr-only">Previous</span></a> <a class="carousel-control-next" href="#lightbox" role="button" data-slide="next"><span class="carousel-control-next-icon" aria-hidden="true"></span><span class="sr-only">Next</span></a> </div> </div> </div> </div> </div> <div id="lg" class="d-none d-lg-block"></div><div id="md" class="d-none d-md-block d-lg-none"></div><div id="sm" class="d-none d-sm-block d-md-none"></div>
.multi-carousel { opacity: 0; padding: 0 25px; } .multi-carousel .carousel-control-next, .multi-carousel .carousel-control-prev { width: 25px; background: gray; }
var $origin = $("#carouselPlus .carousel-inner").prop("outerHTML"); function multiCarousel(){ if ( $( "#lg" ).is( ":visible" ) ) { do { $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid:lt(4)" ).wrapAll( "<div class=\"carousel-item\"><div class=\"row\"></div></div>" ); $( "#carouselPlus .carousel-inner .carousel-item:first" ).addClass("active"); } while ( $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid" ).length ); } else if ( $( "#md" ).is( ":visible" ) ) { do { $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid:lt(3)" ).wrapAll( "<div class=\"carousel-item\"><div class=\"row\"></div></div>" ); $( "#carouselPlus .carousel-inner .carousel-item:first" ).addClass("active"); } while ( $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid" ).length ); } else { do { $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid:lt(1)" ).wrapAll( "<div class=\"carousel-item\"><div class=\"row\"></div></div>" ); $( "#carouselPlus .carousel-inner .carousel-item:first" ).addClass("active"); } while ( $( "#carouselPlus .carousel-inner" ).children( ".carousel-grid" ).length); } } $(window).on( "load resize", function() { $.when( $( "#carouselPlus .carousel-inner" ).replaceWith( $origin ), multiCarousel() ).done(function() { $( ".multi-carousel" ).animate({opacity: "1"}, 1000); }); });

Related: See More


Questions / Comments: