简体   繁体   English

带有引导程序的图像库,带有较大图像的缩略图

[英]Image gallery with bootstrap, thumbnail with bigger image

I am busy with an image gallery, using bootstrap 3. 我正在使用引导程序3忙于图像库。

So if I click on a image you will see the popup - which is nice of course, but the popup doesn't disappear if you click somewhere else / background - it sticks on the screen. 因此,如果我单击图像,您将看到弹出窗口-当然很好,但是如果您单击其他位置/背景,弹出窗口不会消失-它会停留在屏幕上。

My code: 我的代码:

@model  ContosoUniversity.Models.UserProfile

@{
    ViewBag.Title = "Details";
}

@*<h2>Details</h2>*@

<link href="~/Content/ShowMoreImages.css" rel="stylesheet" />



<div class="container">

    <ul>
        <li><img src="~/Images/LCC_logo3.gif" alt="" height=150 width=200 /></li>
    </ul>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    @*</ul>*@
</div> 



    <script>
        $(document).ready(function () {

            $('li img').on('click', function () {
                var src = $(this).attr('src');
                var img = '<img src="' + src + '" class="img-responsive"/>';
                $('#myModal').modal();
                $('#myModal').on('shown.bs.modal', function () {
                    $('#myModal .modal-body').html(img);
                });
                $('#myModal').on('hidden.bs.modal', function () {
                    $('#myModal .modal-body').html('');

                });
            });

            $("#myModal").mouseup(function (e) {
                if (e.target !== this) return;
                $('#myModal').modal('hide');
            });

        });


</script>

Your HTML markup isn't sufficient enough, would have been better if you could F12 and provide the DOM structure of that modal when its in preview mode. 您的HTML标记还不够,如果可以F12并在预览模式下提供该模式的DOM结构,那就更好了。 Looking at your code, I came up with this, added a second function to your script, called Mouseup on $("#myModal") . 查看您的代码,我Mouseup了这一点,并在脚本中添加了第二个函数,在$("#myModal")上称为Mouseup

<script>
$(document).ready(function () {

    $('li img').on('click', function () {
        var src = $(this).attr('src');
        var img = '<img src="' + src + '" class="img-responsive"/>';
        $('#myModal').modal();
        $('#myModal').on('shown.bs.modal', function () {
            $('#myModal .modal-body').html(img);
        });
        $('#myModal').on('hidden.bs.modal', function () {
            $('#myModal .modal-body').html('');

        });
    });

    $("#myModal").mouseup(function (e){
        if( e.target !== this ) return;
        $('#myModal').modal('hide');
    });             

});


</script>

It will hide the modal window, if you click on the faded (outside of the modal box) part. 如果单击褪色(模态框外部)的部分,它将隐藏模态窗口。


Depending on your comments, I am guessing there is something wrong in the markup itself. 根据您的评论,我猜标记本身有问题。 As in multiple elements having the same modal ID, and etc. Take a look at 如多个具有相同模式ID的元素,等等。
Bootstrap 3 Lightbox Bootstrap 3灯箱
a very detailed information, application and examples are provided, shouldn't be hard to create a gallery. 提供了非常详细的信息,应用程序和示例,创建画廊应该不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM