I've created a media gallery where I want to show the images with a colorbox. When I click the image for the first time, it is not shown in the size that is configured in the image style, but it is shown at about 250px width and height.
I tried the max-width: none trick, but this only fixes the height (resulting in a tall but narrow image).
I don't have this issue with other themes. I have observed the issue in Firefox 10 (Aurora) on Windows and Linux, not in IE8 or IE9.
Demo of the issue:
- Go to http://payottenland.com/demo/node/2
- Click the picture, image is small
- Close the colorbox, click the picture again, image has correct size
- Clear recent cache to be able to reproduce this afterwards
Comments
Comment #1
Jeff Burnz commentedCan you try setting the width to auto, this is certainly something to do with colorbox not being able to calculate the correct dimensions of the image until it is cached, which is slightly odd since the explicit dimensions are there in the img tag.
Try something like:
I'm not very confident that will work, I'll need to set this up but time is against me at the moment.
Comment #2
Lapino commentedI tried the suggestion on the demo site, but unfortunately, it does not work.
I'll try to investigate it myself a bit as well, but my time is limited also.
Comment #3
AllyMediaGroup commentedI ran into a similar problem with my colorbox not expanding large enough to show the image clearly. What I found had to be done is in configuration, media, colorbox. There is a place to expand (by a check box if I remember correctly) the advanced options. Then you can change the settings of how the image should render in the colorbox. I set the Max height to 250% and unchecked the box for fixed.
Comment #4
Jeff Burnz commentedHmmm, also try this as well:
Could be the max-width tripping out the JS when its trying to calculate the image size, but really I am guessing, I don't know how this script calculates the correct image size, I thought it took it direct from the img element (some of the docs allude to that), but I don't think thats the whole story...
Comment #5
Lapino commentedI tried both suggestions, but unfortunetaly they don't work. Changing the colorbox settings made it even worse, as only a few pixels of the image are shown now.
The max-width:none code made the height of the picture correct, but the width is still wrong.
Comment #6
Jeff Burnz commentedCan you give me a complete run down of what you are doing here - I just installed Colorbox (latest version) and it works without any issues.
Your lightbox looks different though, yours has gray borders whereas the one I am using is entirely white, and the captions are hidden until you hover the image (they slide up).
You'll need to give me a complete outline of the modules you have installed and your configuration, even better zip your test site up and send it to me or give me a link to download it from somewhere (with the database) so I can install it and pinpoint the exact issue.
Comment #7
Lapino commentedI did some further investigation and I see the issue does not happen with a "regular" colorbox, only with the colorboxes generated by the media gallery module.
The module seems to use it's own instance of colorbox (not from the colorbox module), but there is a "use colorbox" patch available, I'll try to see if this solves the problem.
About the look: that's just a possible theme for the colorbox, but I see the issue with all themes.
Edit: I tried the module integration patch, but it does not change anything. I tried adding width: auto to some more elements (#colorbox, #cboxWrapper,...), but it only gives more strange behaviour.
Comment #8
Jeff Burnz commentedOK, so what we really need to do is figure out what the difference in output of regular Colorbox and Media Gallery Colorbox. I figured this might be the case, since it worked fine with regular Colobox.
Comment #9
AllyMediaGroup commentedI added
to my styles.custom.css and it solved the image problems I was having in IE8.
Comment #10
Jeff Burnz commented@AllyMediaGroup - while you may not care about maintaining the responsive image feature that is up to you, but this "fix" you have posted removes the responsiveness of ALL IMAGES. Its also already been tested (I posted this in #4), and several users, including me, found this to be a bit flaky and unreliable (might work for you, but not others, this is part of the problem).
Comment #11
AllyMediaGroup commented@Jeff - Thank you for the information. And I realize that this is not a "fix". But until I figure out what is causing the issue I needed something to make the client happy. I appreciate all your hard work and so far I have liked Adaptive Themes and may still keep using them in the future. At least until I get better at creating custom themes/subthemes. I removed the media module and went with the regular colorbox and I was still having the issue. So even though I hate to do it, I figured out a hack to make it work. And I do mean I hate to hack anything. So please don't think that I am trying to make it seem that it is a problem with the theme. I just did what I had to do to get my client to stop calling me every couple hours wanting it fixed.
Comment #12
Jeff Burnz commentedAs reported earlier it does work with standard Colorbox already, out of the box, so not sure why you needed to use a fix.
I already know what the problem is, I figured it out ages ago - Media Module is clearly not using a standard Colorbox script - because that script is meant to read the width and height attributes in the image element to get the size (read the Colorbox help, its very clear on how this script is meant to work).
However, when Drupal 7 first shipped the width and height attributes were missing from generated image elements (they were considered a performance issue). I think that Media module tried to work around this by hacking the Colorbox script so it would work without those attributes. In more recent Drupal core releases height and width attributes ARE printed in image elements. Now I have not checked if the script is hacked or not, but simple logic dictates that they did something to make it work without those attributes (it could be a parameter or argument I am not aware of in the script), but me thinks the maintainer hacked it out of necessity - and in doing so created a bunch of issues for responsive themes.
I am actually going to close this as a "won't fix" for now because I cannot see how to keep the responsive images (with our current limited technology in Drupal), and support every single module that tries to treat images in some unique way. When building responsive themes its a simple fact that you need to think differently and seek solutions that work with responsive techniques.
Comment #13
Bester commentedI just had the exact same problem, which only occurred in Firefox and I found something to fix it.
First thing you need to check to make sure that my solution will work is this:
This css must force Firefox to load your image in its full size, even though the frame will still be minuscule and the overflow of the image will be hidden. However, now we can draw the width and height attributes from the image and force Colorbox to resize to the correct height and width. Create a javascript file and put this inside:
(make sure to adjust css anchors if they don't match with yours)
Now flush all cache from Drupal, clear your browser cache and then depending on your Colorbox skin, adjust width and height variables a little bit, because they don't take borders into account, reducing the image size by some 50 pixels or so.
Hope it works for you, Jeff.
Comment #14
rp7 commentedSolution in #13 works for me.
Thanks Bester!
Comment #15
jolidog commentedYou can also add this attributes to images inside colorbox:
When the js runs on the image for resizing it will see the default img height and width and make the correct calculations.
Hope it helps!
Comment #16
deepsoulstarfish commentedI had this issue. It was solved by removing a img {height:auto;} declaration for images earlier in the theme settings.
Comment #17
BryanCGreen24 commentedI'm experiencing this issue-- has it ever been fixed? Is it an issue with the Media Gallery module or the Colorbox module?
Comment #18
lzimmerman commentedI was able to get Firefox to load inline HTML in a colorbox at the correct size by adding a delay to a resize in an OnComplete function: #2301539.
Another issue reported better behavior after removing an img {height: auto} as in #16 (#1421258).
Comment #19
chike#16 solved it for me. As soon as I removed img {height:auto;} declaration from my theme css file, the images started loading in their actual sizes in colorbox!
Comment #20
spruitje commented#16 solved it for me as well! Thanks for that. (I spent ages looking for the right solution)
The {height: auto;} declaration is standard in Drupal Zen Sass files; once removed > problem solved.
Comment #21
jaesperanza commentedSame here! #16 fixed the issue, disabled height: auto; in my theme. Had the issue in both firefox and chrome.