Topic: Space above and below image on responsive page [SOLVED]

I have used Juicebox on a fixed width webpage, setting the size of the gallery on a DIV that wraps the juicebox-container, and that worked well.

Now I am changing to a responsive page design and testing how the juicebox gallery looks. It is responsive, but there is always space above and below the image. I have read other threads and tried what they suggested, but I cannot get rid of this space.

My images are 1024 x 768. I display buttons on top, thumbnails below and caption overlay-image. imageScaleMode is left to the default.

This is my test page: http://www.sloweurope.com/test-pk/

How can I get rid of that space?

Re: Space above and below image on responsive page [SOLVED]

Please see this FAQ which may help:
My Juicebox gallery shows too much space above or below the main image, how do I fix this?

If your gallery is responsive and its dimensions change depending on the size of the user's browser window, then you essentially have no control over the size and shape of your gallery. Juicebox will, by default, scale images to fit within the gallery's image area (no matter what its size), respecting their aspect ratios and without cropping. If the aspect ratio of the image does not match that of the gallery's image area, then there will be space to the top and bottom or to the left and right of the image.
The easiest ways to avoid this would be to:
(1) Use absolute pixel values (rather than percentages) for the gallery's dimensions and make sure that the aspect ratio of the gallery's image area matches that of the images themselves.
... or:
(2) Change the imageScaleMode (in JuiceboxBuilder-Pro's 'Customize -> Main Image' section) to a value such as 'FILL' so that Juicebox always fills the image area (although please note that cropping may occur).

A further option would be to allow your gallery's dimensions to scale (when the browser window's width changes) but for its aspect ratio to always remain the same. This would require some JavaScript code to resize the gallery, maintaining its aspect ratio when the browser window is resized. (This would not ordinarily happen. If you change the width of your browser window, a div on a web page may have its width altered but not its height.)
Try the following.
Create a sample gallery with JuiceboxBuilder-Pro and use the following code as the gallery's 'index.html' page.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" id="jb-viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <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 jb;
            function doLayout() {
                var windowWidth = parseInt(window.innerWidth ? window.innerWidth : $(window).width(), 10);
                var galleryWidth = parseInt(windowWidth * 0.8, 10);
                var galleryHeight = parseInt(galleryWidth / 2, 10);
                $('#wrap').width(galleryWidth);
                $('#wrap').height(galleryHeight);
                if (jb) {
                    jb.setGallerySize(galleryWidth, galleryHeight);
                }
            }
            $(document).ready(function() {
                $(window).resize(doLayout);
                jb = new juicebox({
                    containerId: "juicebox-container"
                });
                doLayout();
            });
        </script>
        <title>Test</title>
    </head>
    <body>
        <div id="wrap">
            <div id="juicebox-container"></div>
        </div>
    </body>
</html>

The '0.8' value is just an arbitrary width for the gallery (80%) for this example. You can change this to whatever you like.
The aspect ratio in the above example is 2:1 (set by the '2' in the line var galleryHeight = parseInt(galleryWidth / 2, 10);).
Again, you can change this to whatever you like.
I hope this points you in the right direction and that you are able to implement a suitable solution into your own web page.

Re: Space above and below image on responsive page [SOLVED]

If I do (1) the gallery looks fine full size but as you make the page smaller the space appears above and below the image.

If I do (2) and use FILL it works, but as you said, the images are cropped.

What do people do who want to embed a gallery on a responsive page? Is the best option to use a splash page and force users to view the gallery fullsize?

Re: Space above and below image on responsive page [SOLVED]

I missed the last part of your post and will try that new code now.

Re: Space above and below image on responsive page [SOLVED]

I added the code and sized it so it fits well when the page is full size. When the page size is reduced, it is responsive and there is no space before and after the image, but the gallery (the stage) gets much smaller than the rest of the column. When it gets to one column the gallery is not the width of the column.

http://www.sloweurope.com/test-pk/jbtest-newcode.php

Re: Space above and below image on responsive page [SOLVED]

My conclusion, for today, is to use a Splash Page linking to the full browser photo gallery. The Splash image is responsive. The full browser photo gallery looks good on desktop and iPad.
Example of Splash Page: http://www.sloweurope.com/test-pk/

But, I would like to use an embedded gallery, like I did on the fixed width version of the website. If anyone has been successful doing this, embedding into a section of the website, please let me know how you did it.
Example of how it works embedded into a fixed width page: http://www.sloweurope.com/photo/17/aveb … ne-circle/

Re: Space above and below image on responsive page [SOLVED]

I missed the last part of your post and will try that new code now.

It looks like I was editing my first post whilst you were posting your reply.

If I do (1) the gallery looks fine full size but as you make the page smaller the space appears above and below the image.

This is normal. The shape of your gallery changes (when the browser window's dimensions change) but the shape of your image does not.

If I do (2) and use FILL it works, but as you said, the images are cropped.

If you want the image to fill the gallery's image area without cropping, then the shape of the image must match the shape of the gallery's image area. Otherwise, the image will be cropped (if you want to fill the image area) or space will be introduced (if you want the image to be scaled to fit within the image area without cropping).
The only way to ensure that the shape of the gallery's image area matches the shape of your images is to control the gallery's dimensions (either by fixing the gallery's dimensions using absolute pixel values or by assigning new dimensions to your gallery using JavaScript whenever the browser window is resized).

Is the best option to use a splash page and force users to view the gallery fullsize?

This would certainly be another option.

When the page size is reduced, it is responsive and there is no space before and after the image, but the gallery (the stage) gets much smaller than the rest of the column.

In your case (with a two column layout), you do not want the gallery's width to be a percentage of the entire window width (which you currently use) but rather it should always be 100% of its parent container's width.
Try changing:

var galleryWidth = parseInt(windowWidth * 0.425);

... to something like:

var galleryWidth = parseInt($('#article').width());

Hopefully this will help.

Re: Space above and below image on responsive page [SOLVED]

Thank you Steven, that did it. The gallery is responsive within that column of my website and looks good on the iPad!!

Re: Space above and below image on responsive page [SOLVED]

That's great!
Thanks for posting back to let me know.