简体   繁体   English

jQuery Lightbox图片大小:限制图片的最大大小

[英]jQuery Lightbox Image Size : Limit the max size of Image

I have images which are larger than the screen's viewport, when using them with jQuery Lightbox, the images are showing up in the original size, and hence to see the complete image one needs to scroll horizontally and vertically. 我有大于屏幕视口的图像,将它们与jQuery Lightbox一起使用时,图像以原始尺寸显示,因此要查看完整的图像,需要水平和垂直滚动。 I have tried using the CSS tweaks available online but they do not seem to be working. 我尝试使用在线提供的CSS调整,但是它们似乎无法正常工作。 I tried the following code. 我尝试了以下代码。

#lightbox-container-image-box {
  max-width:900px ! important; // Or your max-width
}

#lightbox-container-image img {
 max-width:675px ! important; // (your max width - 20)
}

So, what I want to do is set a maxWidth and maxHeight to the lightbox view, ideally do not want to change the lightbox.js file as it is being used at multiple other places. 因此,我想为lightbox视图设置一个maxWidth和maxHeight,理想情况是不想更改lightbox.js文件,因为该文件正在其他多个地方使用。

try adding width % 尝试添加宽度%

#lightbox-container-image-box {
  max-width:900px ! important; // Or your max-width
  width: 100%; //use 100% of even 90% , see what works for you
}

#lightbox-container-image img {
 max-width:675px ! important; // (your max width - 20)
 width: 100%; 
}

If it is the plugin by Lokesh Dhakar for me the css script below has solved the problem. 如果它是我的Lokesh Dhakar插件,则下面的CSS脚本已解决了该问题。

At end of file lightbox.css you write this 在文件lightbox.css的末尾,您可以编写以下代码

#lightbox-container-image-box {
    max-width: 80%;
    height:100% !important;
}
#lightbox-container-image img {
    max-width: 100%; 
}
#lightbox-container-image-data-box{ 
    max-width:80%; margin-bottom:50px;
}

Warning : #lightbox-container-image-box and #lightbox-container-image-data-box must have the same max-width 警告 :#lightbox-container-image-box和#lightbox-container-image-data-box必须具有相同的最大宽度

if you want you can set max-width in px. 如果需要,可以设置最大宽度(以px为单位)。

GitHub project link GitHub项目链接

Website project link 网站项目链接

if you have all them images with small size and want to show in large size then test it find these lines in jquery.colorbox.js 如果所有图像都较小,并且要大尺寸显示,请进行测试以在jquery.colorbox.js中找到这些行

photo.style.width = photo.width + 'px'; photo.style.width = photo.width +'px'; photo.style.height = photo.height + 'px'; photo.style.height = photo.height +'px';

comment the hight line for image ratio like 评论高行的图像比率,例如

//photo.style.height = photo.height + 'px'; //photo.style.height = photo.height +'px';

and increase image width with ratio hight photo.style.width = photo.width+200 + 'px'; 并以较高的比例增加图像宽度photo.style.width = photo.width + 200 +'px';

I know the question was asked a year ago, but since @Sompuperoo answer helped me, it might be usefull to others. 我知道这个问题是一年前提出的,但是由于@Sompuperoo的回答对我有所帮助,因此对其他人可能有用。

Here is what I used (In my case the image was larger than screen size) : 这是我使用的内容(在我的情况下,图像大于屏幕尺寸):

#lightbox-container-image-box {
    max-width: 100%;
    height:100% !important;
}
#lightbox-container-image img {
    max-width: 100%; 
}

After spending a lot of time in trying to make lightbox responsive, I had to give up, script is too old and unadequate. 在花了很多时间试图使灯箱响应之后,我不得不放弃,脚本太旧且不足。

Now I'm using Featherlight: https://noelboss.github.io/featherlight/ , almost identical to lightbox but fully responsive (and also very easy to use). 现在,我正在使用Featherlight: https ://noelboss.github.io/featherlight/,与lightbox几乎相同,但响应迅速(也非常易于使用)。

JSFiddle demo: https://jsfiddle.net/2pznx9vL/ JSFiddle演示: https ://jsfiddle.net/2pznx9vL/

<link href="//cdn.rawgit.com/noelboss/featherlight/1.7.13/release/featherlight.min.css" type="text/css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-latest.js"></script>
<script src="//cdn.rawgit.com/noelboss/featherlight/1.7.13/release/featherlight.min.js" type="text/javascript" charset="utf-8"></script>
<a href="https://hdfreewallpaper.net/wp-content/uploads/2016/10/Norway-Balloon-Beautiful-Scenery-Wallpaper.jpg" data-featherlight="image"><IMG SRC="https://hdfreewallpaper.net/wp-content/uploads/2016/10/Norway-Balloon-Beautiful-Scenery-Wallpaper.jpg" style='width:150px'><br>click on image</a>

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

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