Bootstrap Thumbnail with Modal Lightbox


<h1>Click on image to open modal</h1>
<br/>

	<div class="container">
    <div class="col-xs-6 col-sm-3">
        <a href="javascript:;" class="thumbnail" data-toggle="modal" data-target="#lightbox"> 
            <img src="http://getuikit.com/docs/images/placeholder_800x600_1.jpg" alt="click here !">
        </a>
    </div>
    <div class="col-xs-6 col-sm-3">
        <a href="javascript:;" class="thumbnail" data-toggle="modal" data-target="#lightbox"> 
            <img src="http://getuikit.com/docs/images/placeholder_800x600_2.jpg" alt="click here !">
        </a>
    </div>
    <div class="col-xs-6 col-sm-3">
        <a href="javascript:;" class="thumbnail" data-toggle="modal" data-target="#lightbox"> 
            <img src="http://getuikit.com/docs/images/placeholder_800x600_3.jpg" alt="click here !">
        </a>
    </div>
    <div class="col-xs-6 col-sm-3">
        <a href="javascript:;" class="thumbnail" data-toggle="modal" data-target="#lightbox"> 
            <img src="http://getuikit.com/docs/images/placeholder_800x600_4.jpg" alt="click here !">
        </a>
    </div>
</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="">
            </div>
        </div>
    </div>
</div>
	<script type="text/javascript"></script>

    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() {
    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
            };
    
        $lightbox.find('.close').addClass('hidden');
        $lightbox.find('img').attr('src', src);
        $lightbox.find('img').attr('alt', alt);
        $lightbox.find('img').css(css);
    });
    
    $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');
    });
});