简体   繁体   English

大于屏幕分辨率时,弹出图像查看器不会调整图像大小

[英]popup image viewer doesn't resize the image when it is bigger than the screen resolution

I'm working with Bootstrap, i used this template of Gallery Image . 我正在使用Bootstrap,我使用了Gallery Gallery模板。

The website demo works great because the images are horizontal : 该网站演示非常有效,因为图像是水平的:

在此处输入图片说明

But when i edited the code and put my picture (which are verticals), i think it is trying to fill them horizontally so the image isn't visible at 100%. 但是,当我编辑代码并放入图片(垂直)时,我认为它试图水平填充图片,因此图像在100%时不可见。

错误

How can i fix that, here is the code i think (I'm newbie so I'm not sure) : 我该如何解决,这是我认为的代码(我是新手,所以不确定):

<script>
                popup = {
                    init: function(){
                        $('figure').click(function(){
                            popup.open($(this));
                        });

                        $(document).on('click', '.popup img', function(){
                            return false;
                        }).on('click', '.popup', function(){
                            popup.close();
                        })
                    },
                    open: function($figure) {
                        $('.gallery').addClass('pop');
                        $popup = $('<div class="popup" />').appendTo($('body'));
                        $fig = $figure.clone().appendTo($('.popup'));
                        $bg = $('<div class="bg" />').appendTo($('.popup'));
                        $close = $('<div class="close"><svg><use xlink:href="#close"></use></svg></div>').appendTo($fig);
                        $shadow = $('<div class="shadow" />').appendTo($fig);
                        src = $('img', $fig).attr('src');
                        $shadow.css({backgroundImage: 'url(' + src + ')'});
                        $bg.css({backgroundImage: 'url(' + src + ')'});
                        setTimeout(function(){
                            $('.popup').addClass('pop');
                        }, 10);
                    },
                    close: function(){
                        $('.gallery, .popup').removeClass('pop');
                        setTimeout(function(){
                            $('.popup').remove()
                        }, 100);
                    }
                }

                popup.init()

            </script>

The size of image in this demo is fully specified via CSS rules, thus you can add a max-height rule to constraint the maximum height of image. 此演示中图像的大小完全通过CSS规则指定,因此您可以添加max-height规则来限制图像的最大高度。

You can modify the rule of .popup figure img to following rule sets: 您可以将.popup figure img的规则修改为以下规则集:

.popup figure img {
  position: relative;
  z-index: 2;
  border-radius: 15px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2), 0 6px 30px rgba(0, 0, 0, 0.4);
  max-height: calc(100vh - 50px);
}

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

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