|
Another Lightbox hack
2006.07.25 1:25 PM
NOTICE: CONTENTS NO LONGER APPLICABLE The content discussed in this post is no longer valid; as I’m now using a different “lightbox” implementation. When opening an image via lightbox, closing an image can get very counter intuitive. The close button is at the bottom right, which sucks if you have an image that’s larger than the viewing area. Trying to move that close button on the upper right can be too tedious as it requires a lot of modification on the A hack for this is easy to do, however this usually broke Lightbox‘s “group” mode – instead of moving to the previous/next image, it prioritizes the close function assigned to the image container instead of the group mode’s prev/next overlays – resulting in the image closing anywhere you click. The trick was to find another place where I could inject similar code, while making sure that it only does it when it’s viewing a single image. As of v2.02, search for this code (should be somewhere around line 436) // if image is part of set display ‘Image x of x’ if(imageArray.length > 1){ Element.show(‘numberDisplay’); Element.setInnerHTML( ‘numberDisplay’, “Image ” + eval(activeImage + 1) + ” of ” + imageArray.length); } Replace the last document.getElementById(‘imageContainer’).onclick = function() { return false; } } else { document.getElementById(‘imageContainer’).onclick = function() { myLightbox.end(); return false; } } What this does is it applies the By that logic, you can simply say that adding an If you’re asking why I seemingly put a blank DemonstrationThese first two engage a single-mode lightbox view, hence you should be able to close the lightbox by clicking anywhere on the image. These next two are the same images, but now grouped in a set. You should be able to click on the next/prev overlay without accidentally closing the lightbox. |
Thanks for the hack. It seems to work well so far. Is there an easy way to get the cursor to change into a pointer so that it looks like you can click?
Good question, I’m not sure if this will work, but it probably could.
Look for the part of the code which says:
var objImageContainer = document.createElement("div");
objImageContainer.setAttribute('id','imageContainer');
objOuterImageContainer.appendChild(objImageContainer);
and change it to:
var objImageContainer = document.createElement("a");
objImageContainer.setAttribute('id','imageContainer');
objImageContainer.setAttribute('href','#');
objOuterImageContainer.appendChild(objImageContainer);
And if ever it messes up alignment and other stuff, try fixing the CSS (display:block or clear:both etc.) to make it behave like a DIV
Again, I didn’t bother testing this because I really don’t intend to implement it this way, but logically it should work (I hope)
Nope, it didn’t do anything… I didn’t change any css since it really didn’t change anything.
I wish I knew more about coding, but I don’t.
Thanks again for the hack. (also, the live preview isn’t live previewing – I’m using FF 1.5.0.5 for the Mac)
Excellent!
Thanks alot for this nice little hack, now I can remove that ugly close-button.
|
777 words
|
Been a while since I posted. While there may be some stuff I would want to blog about, I’m not feeling “profound” these days.
Instead,…
|
|



cool hack dude!