JQuery LightBox Max Height and Width

I needed lightbox 2 functionality for a project I'm working on, but didn't want the overhead of having to include prototype, scriptaculous, et al that comes with it since we are already using JQuery.  I found the excellent JQuery lightbox plugin written by Leandro Vieira Pinho and works well, but I needed to be able to set the max height and width so I had to mod the code as follows:

settings = jQuery.extend({ maxWidth: null, maxHeight: null,

...

function _resize_container_image_box(intImageWidth,intImageHeight) { //rescale if necessary if((settings.maxWidth != null && settings.maxHeight != null) && (intImageWidth > settings.maxWidth || intImageHeight > settings.maxHeight)){ var isWider = intImageWidth > intImageHeight;//is the image wide or tall? var scale = isWider ? settings.maxWidth/intImageWidth : settings.maxHeight/intImageHeight; intImageWidth = intImageWidth * scale; intImageHeight = intImageHeight * scale; }

 $('#lightbox-image').height(intImageHeight); 
 $('#lightbox-image').width(intImageWidth);  

...

Now you can specify a max width and height like:

$('.yourClass a').lightBox({
        maxHeight: 500,
        maxWidth: 700
});
This article is part of the GWB Archives. Original Author: Scott Wojan

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.