4

I have been trying to figure out how to make BC's photogallery lightbox responsive. I don't know why they wouldn't make it responsive in the first place, but whatever. Here is the webpage I am working on: http://ladyilgphotography.businesscatalyst.com/family-photography

Here is what I have so far.

<script>
    $('body').click(function() {document.getElementById('outerImageContainer').onclick=function(){
        var elem = document.getElementById('outerImageContainer');
        var newWidth = 0;
        var newHeight = 0;
        var w = parseInt(elem.style.width);
        var h = parseInt(elem.style.height);
        var ratio = parseInt(w / h);
        newWidth = window.innerWidth - 80;
        alert(newWidth);
        newHeight = parseInt(newWidth * ratio);
        elem.style.width = newWidth + 'px';
        elem.style.height = newHeight + 'px';
    };});
</script>

I'm sure this is not the cleanest solution or the most effective, but it's working!

The problem is that the script runs as soon as the picture is loaded, and then Business Catalyst's script runs after which resets the values my function had set.

Another solution that I thought about was just to add a 95% max-width to the "#outerImageContainer", but when I do that, it starts breaking down after a few clicks through the gallery and the image starts shifting farther and farther down on the page while the lightbox wrapper stays the same.

Lastly, I tried using another photo gallery plugin, but the only problem with that is that plugins like pretty photo or photoswipe only target the images that are loaded on the page, but in my case, there are more images in the gallery than the ones showing on the page.

To summarize my rant, again, how can I make BC's lightbox responsive so that both the width and the height match those of the image being loaded on it?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
nvncbl
  • 179
  • 1
  • 2
  • 15
  • 1
    @Andrew T, SO is telling me you edited the code, but i don't see any changes. did i miss something? Thanks for your help. – nvncbl Aug 09 '14 at 18:30
  • 1
    I just added some new lines to make it easier to read. And no problem, although sorry I can't help with the issue as I'm not an expert at those field. – Andrew T. Aug 09 '14 at 18:36

1 Answers1

6

I use these few rules of CSS to enforce fluid size on BC's Lightbox modal popup:

#outerImageContainer {
    max-width: 90%;
    overflow: hidden;
    height: auto !important;
}

#imageDataContainer {
    max-width: 90%;
    overflow: hidden;
}

#lightboxImage {
    max-width: 100%;
}

No other JS or HTML changes required. Here's a quick video demo: http://gfycat.com/GraveUntriedGuineapig.

Another solution that I thought about was just to add a 95% max-width to the "#outerImageContainer", but when I do that, it starts breaking down after a few clicks through the gallery and the image starts shifting farther and farther down on the page while the lightbox wrapper stays the same.

I can't reproduce that on Chrome, Firefox or IE11. Could it be some other JS/CSS on the page? What browsers is it occurring in?


EDIT: A workaround for the 'growing height' issue, thanks to @nvncbl: apply font-size: 0 !important to #outerImageContainer.

Community
  • 1
  • 1
Robert K. Bell
  • 9,350
  • 2
  • 35
  • 50
  • 1
    Thank you Clement. this was so simple! I wish I had seen this sooner as I spent all of last night hooking up fancybox with my site. Definitely answered my question though. – nvncbl Aug 11 '14 at 16:26
  • 1
    Clement, would you do me a favor? Go to http://11thavenuehotelandhostel.businesscatalyst.com/rooms, click on one of the room pictures, and resize the browser. I am getting the same problem I was getting before. When I resize, the image keeps moving farther and farther down inside the lightbox. I tried it in both ie10 and latest chrome version (37.*?) – nvncbl Oct 11 '14 at 19:26
  • 3
    Never mind. I think I figured it out. Just for your reference, in case it ever happens to you, add a font-size:0!important; to your #outerImageContainer and it should work. thank you – nvncbl Oct 11 '14 at 19:33
  • 1
    Yes, I had the same problem. Not sure exactly what's going on but I can see that without setting font-size to 0 that BC's JS recalculates the font-size on #outerImageContainer every time a thumbnail is clicked and gets itself into all sorts of trouble - the font-size gets bigger and bigger every time, resulting in insane heights on the lightbox container. – Luke Nov 10 '15 at 00:51