Topic: images are responsive, container is not

I'm trying to embed a Juicebox gallery into a responsive website and am finding that the image will respond nicely but that I cannot get the background to stay within the height and width of the images. In other words, the gallery takes up more space than it should because the container is much taller than the images. I tried adjusting this with a percentage height but found as the container window was resized, the percentage height would no longer be correct (i.e. setting 50% height might work at full screen, but not at a tablet size).

How can I keep the container to the same height as the photo?

As an example:
http://movementsystemspt.com/2015/wp-co … embed.html

or within Wordpress

http://movementsystemspt.com/2015/

Re: images are responsive, container is not

setting 50% height might work at full screen, but not at a tablet size

Your sample gallery is not a fully formed web page. There is no Doctype Declaration, <head> or <body> tags.
After creating your gallery with JuiceboxBuilder-Pro, try using or modifying the gallery's 'index.html' page rather than uploading an HTML file with just the gallery's embedding code. The gallery's embedding code really needs to be within a complete and valid HTML web page, otherwise Juicebox may not be able to determine its actual height (if a percentage height is used) and different browsers may treat the isolated HTML snippet differently. A complete and valid web page should provide more predictable and consistent results across different browsers.

Also, your 'juicebox-container' <div> is nested inside a parent 'container' <div> which has not been assigned a height via CSS. If your gallery's height is defined as 100% (for example), then it will be 100% of the height of the parent container. Try explicitly assigning a height to the parent container via CSS. Please also see the note regarding Using Percentage Heights in the Embedding in a HTML Page support section.

How can I keep the container to the same height as the photo?

If all your images are the same height and you just want your gallery to be taller, then set your gallery's height to be a large fixed pixel value (rather than a percentage).
If you really want to gallery's height to change depending on the height of the image which is currently being displayed, then you will need to use JavaScript to check the image's height (each time a new image is displayed) and adjust the height of the gallery accordingly. You would need to use the Juicebox-Pro API's onImageChange() event and setGallerySize() method.
(Usually, each time a new image is displayed, the gallery's dimensions remain constant and the new image is scaled to fit within the gallery's image area.)

Re: images are responsive, container is not

Thank you! I will give those things a try.

Re: images are responsive, container is not

Steven wrote:

If you really want to gallery's height to change depending on the height of the image which is currently being displayed, then you will need to use JavaScript to check the image's height (each time a new image is displayed) and adjust the height of the gallery accordingly. You would need to use the Juicebox-Pro API's onImageChange() event and setGallerySize() method.
(Usually, each time a new image is displayed, the gallery's dimensions remain constant and the new image is scaled to fit within the gallery's image area.)

Can you provide a code snippet? I can't find how you can determine the current image's actual height. Thanks.

Re: images are responsive, container is not

Here's an example of how you can find the actual height of the current image being displayed in the gallery (using JavaScript and the Juicebox-Pro API).
Just create a sample gallery with JuiceboxBuilder-Pro and use the following code as the gallery's 'index.html' file:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <style type="text/css">
            body {
                margin: 0px;
            }
        </style>
        <script type="text/javascript" src="jbcore/juicebox.js"></script>
        <script type="text/javascript">
            var jb = new juicebox({
                containerId: "juicebox-container"
            });
            jb.onImageChange = function(e) {
                var index = e.id;
                var info = jb.getImageInfo(index);
                var url = info.imageURL;
                var image = new Image();
                image.src = url;
                var height = image.height;
                alert('Actual height of current image is ' + height + 'px.');
            };
        </script>
        <title>Test</title>
    </head>
    <body>
        <div id="juicebox-container"></div>
    </body>
</html>

Please note that this will provide the actual height of the file in the 'images' folder (not the height at which the image is displayed in the gallery which will depend on factors such as the gallery dimensions, the browser window size and whether or not gallery elements reserve space in the gallery reducing the available image area).

If you wanted to act upon the actual height of the current image and change the gallery's height to suit the current image's height you could do something like the following:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" id="jb-viewport" content="minimal-ui" />
        <style type="text/css">
            body {
                margin: 0px;
            }
            #wrap {
                width: 100%;
            }
        </style>
        <script type="text/javascript" src="jbcore/juicebox.js"></script>
        <script type="text/javascript">
            var widthInteger = 600;
            var widthString = widthInteger.toString();
            var jb = new juicebox({
                containerId: "juicebox-container",
                galleryHeight: "400",
                galleryWidth: widthString,
                imageScaleMode: "SCALE"
            });
            jb.onImageChange = function(e) {
                var index = e.id;
                var info = jb.getImageInfo(index);
                var url = info.imageURL;
                var image = new Image();
                image.src = url;
                var height = image.height;
                var width = image.width;
                var newHeight = Math.floor((widthInteger/width)*height) + 105;
                jb.setGallerySize(widthString, newHeight);
            };
        </script>
        <title>Test</title>
    </head>
    <body>
        <div id="wrap">
            <div id="juicebox-container"></div>
        </div>
    </body>
</html>

The gallery would have a constant width (600px in the example) and its height would be dependent on the height of the current image. The '105' value adds enough height to the gallery to accommodate the thumbnails and the thumbnail padding at their default values of '85' and '10' (top and bottom).