Lightbox is really a great thing to use but there is one thing I would like to change:
Is there a possibility that every picture which is bigger then the open window is rezized so that it is totally shown in the current window and I don't need to use the scrollbar? I know that there is a hack for version 1 calles lightbox plus but I really would enjoy to have that resize feature in the version 2.
The Lightbox code fails to set a width and height on the "img" tag it creates, so to control that, you need a custom script that adds that back in. Remember, you can put any width and height you want on an image element no matter what its real size....the browser will scale it down or up to fit. So, a better solution to the above is to just add the following inside the lightbox.js file, and "changeImage" function:
After this line "Element.setSrc('lightboxImage', imageArray[activeImage][0]);" add the following:
Substitute "480" with the maximum allows width or height you need in your display. This way, no matter what images are uploaded, they will always fit into the display page. I like 480 pixels as it works on all desktop monitors.
Lokesh: is there any way you can incorporate this into your existing codebase so the next version is easy to work with for resizing? It would be an awesome feature, as well as a very desired one so nobody has to modify the codebase. The method stated here is probably the best one I've seen yet to implement it.
Is there anyway of intergrating this so that it automaticly resizes the image to fit the browser window? (rather that setting a max height?) i know this has been done in lightbox_plus (http://serennz.sakura.ne.jp/toybox/lightbox/) but the gui seems a bit clumsy..
Here's the entire code (Stormy's code) with the Safari fix:
After this line "Element.setSrc('lightboxImage', imageArray[activeImage][0]);" add the following: ---------------------------------------------------------- var maxHeight = 480; var maxWidth = 480;
I have something what can resolve yours problem. its very simple, i just input modified part of code from LyteBox in to code presented by VinDSL, and I get. auto resize image, to fit image to the browser window. insert the same place as VinDSL.
// // changeImage() // Hide most elements and preload image in preparation for resizing image container. // changeImage: function(imageNum) {
activeImage = imageNum; // update global var
// hide elements during transition if(animate){ Element.show('loading');} Element.hide('lightboxImage'); Element.hide('hoverNav'); Element.hide('prevLink'); Element.hide('nextLink'); Element.hide('imageDataContainer'); Element.hide('numberDisplay');
imgPreloader = new Image();
// once image is preloaded, resize image container and // the image so it's no bigger than the current window imgPreloader.onload=function(){ Element.setSrc('lightboxImage', imageArray[activeImage][0]);
// start hack by gr3lla/////////////////CODE ORIGINAL WRITTEN BY Markus F. Hay -LyteBox//////////////////////////////////////////////////////////////////////////////////////////////////// var pageSize = getPageSize(); var x = pageSize[2] - 150; var y = pageSize[3] - 150;
I tried to use your code, gr3lla, but 1. it doesn't work in Safari (the images don't resize), and 2. it disables LightBox completely in Firefox. Maybe I did it wrong; I added your code up there (right above my comment!) to lightbox.js after the line "Element.setSrc('lightboxImage', imageArray[activeImage][0]);"
is that correct?
Any idea why it wouldn't work?
Thank you for anybody's input on this! If I can't find a solution, I'll just upload pictures that fit most standard screens, but it's a shame for those with a big 30 incher, or for those stuck on 800x600...
hmmm... thats strange karlotta i use Firefox 2.0.0.9, and i IE 6.0.2900.2180xpsp2 and in both browsers LightBox works correctly, you can see it on my web page http://gr3lla.go.pl in gallery.
karlotta, did you add my code or replace existing code?? Maybe this is the problem! You should replace original code with my code.
I hope this help more, this is the link directly to the edited .js file. // http://www.gr3lla.go.pl/upload-gr3lla/download.php?load=lightbox.js //
Then I tested it with MSIE 6 & 7, Firefox 2, and Safari 3 beta.
Works fine as far as I can tell... :)
// // changeImage() // Hide most elements and preload image in preparation for resizing image container. // changeImage: function(imageNum) {
activeImage = imageNum; // update global var
// hide elements during transition if(animate){ Element.show('loading');} Element.hide('lightboxImage'); Element.hide('hoverNav'); Element.hide('prevLink'); Element.hide('nextLink'); Element.hide('imageDataContainer'); Element.hide('numberDisplay');
imgPreloader = new Image();
// Once image is preloaded, resize image container and // the image so it's no bigger than the current window imgPreloader.onload=function(){ Element.setSrc('lightboxImage', imageArray[activeImage][0]);
Enabling both VinDSL's and gr3lla's final script changes gives me a fairly substantial space between the image and the edge of the window in IE 6 and Win Firefox. Is there a way to reduce that space? (Thanks to everyone for working on this issue.)
/ start hack by gr3lla/////////////////CODE ORIGINAL WRITTEN BY Markus F. Hay -LyteBox//////////////////////////////////////////////////////////////////////////////////////////////////// var pageSize = getPageSize(); var x = pageSize[2] - 150; var y = pageSize[3] - 150;
I think the text that follows each line is just his pointers to what these variables do. Thanks gr3lla. I will try that out.
I'm confused. I tried VinDSL's hack in IE7, and all I got was the image on a plain white background, on the left side of the screen - no actual Lightbox elements appeared at all, no caption, no close button, nothing. IE7 also tried to tell me there was a colon missing from line 422, but I have no idea where line 422 might be. In my code, which works just fine with the original unhacked lightbox, line 422 happens to be in the middle of a php generated series of table elements giving details of my photos from a MySQL database, and if there was an error in one of those the same error would appear dozens of times before and after line 422 - 100 times, to be precise since there are 100 photos listed on the page.
I swapped over to the lightbox.js downloaded from the link gr3lla gave. That gave me a working lightbox image, except that it did not fill the screen. It had been resized downwards (and very badly, with ugly jaggies). My 1024x683 image was appearing as about 640x427. A smaller version of the same image appeared at about the right size but also mysteriously had ugly jaggies.
I am using this construction in php:
echo 'a href="' . $LPic . '" rel="lightbox" title="' . $row[1] . '"><img src="large.jpg" title="Click to bring up 1024 pixel image</a>';
$LPic is a variable containing the name of the jpg to pull up, $row[1] is the title (caption) of the photo: both are derived from the database. My link is an image of a button marked "large", large.jpg. This all works fine to pull up a small image, so I can't see that it would give any trouble with a larger one.
I just tested the latest version of the 'resize hack' from VinDSL on Nov 16th 2007, and it really works wonderfully! Except in Safari 2.0.4 on a Mac, in Safari beta 3 on Windows it works fine!
@ outtacontext: I think you mean the change in the padding of the imageContainer, right? You can solve that by changing the lightbox.css like this:
Any idea if this still works in v2.04? I've tried finding "Element.setSrc('lightboxImage', imageArray[activeImage][0]);" so I could put the 'resize hack' from VinDSL on Nov 16th 2007 after it but can't find it.
Help! I have tried every iteration of Vin's code and I keep getting the same error 'animate not found'. It is defined at the top so I am not sure what the issue is....any ideas?
I have found (at least in my .js file) that I am having to edit the changes to put in things like VAR that is missing or adding the this. to the activeImage and imageArray elements in the code. This gets rid of specific errors but now I am getting another error that says "'this.imageArray' is null or not an object.' I am currently searching for missing parens and brackets to see if this is the issue.....
Hy guys. I have updated the latest v2.04 version to resolve some issues and implement the automatic resizing feature. Details are in my blog http://blog.hma-info.de/2008/04/09/latest-lightbox-v2-with-automatic-resizing/ Hope that helps! .: Fabian