"Untitled"
Bootstrap 4.1.1 Snippet by truptimotu

<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"> <!-- image area container --> <div class="col-xs-6 col-sm-3"> <!-- Duplicate this div and change , or generate from each/loop with dynamic content --> <a href="#" class="thumbnail" data-toggle="modal" data-target="#lightbox"> <img src="http://localhost/mynew/assets/images/fabrictype/1574416426Penguins.jpg" alt="..."> <!-- change just image url and alt attribute --> </a> </div> </div> <!-- lightbox div --> <div id="lightbox" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> <div class="modal-dialog"> <button type="button" class="close hidden" data-dismiss="modal" aria-hidden="true">×</button> <div class="modal-content"> <div class="modal-body"> <img src="" alt="" /> <!-- this IMG tag receives dynamic image data/info --> </div> </div> </div>
body { padding: 30px 0px; } #lightbox .modal-content { display: inline-block; text-align: center; } #lightbox .close { opacity: 1; color: rgb(255, 255, 255); background-color: rgb(25, 25, 25); padding: 5px 8px; border-radius: 30px; border: 2px solid rgb(255, 255, 255); position: absolute; top: -15px; right: -55px; z-index:1032; }
(document).ready(function() { // Change image in lightbox based on click event var $lightbox = $('#lightbox'); $('[data-target="#lightbox"]').on('click', function(event) { var $img = $(this).find('img'), src = $img.attr('src'), alt = $img.attr('alt'), css = { 'maxWidth': $(window).width() - 100, 'maxHeight': $(window).height() - 100 }; // find and change attributes $lightbox.find('.close').addClass('hidden'); $lightbox.find('img').attr('src', src); $lightbox.find('img').attr('alt', alt); $lightbox.find('img').css(css); }); // show modal as lightbox with clicked image $lightbox.on('shown.bs.modal', function (e) { var $img = $lightbox.find('img'); $lightbox.find('.modal-dialog').css({'width': $img.width()}); $lightbox.find('.close').removeClass('hidden'); }); });

Related: See More


Questions / Comments: