-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new feature : make a responsive colorbox #158
Comments
Any updates on this request? |
This would be very nice. I was trying to see if I could hack at it bit by putting in a binding to orientationchange, but I don't understand how the publicMethod.resize function gets called, which is I think what I want to happen. I tried this, and it seemed to work right for switching from portrait to landscape, but NOT back the other way. In fact, my image kept getting bigger. Yikes! I put this right the binding of "resize." + prefix. (I guess resizing the window currently only repositions the image, does not shrink or enlarge it. But for changing orientation we need to resize the image!
|
Hi, I still have not found a solution to auto resizing colorbox when changing orientation of the mobile device. Does anyone know if it's possible to get ColorBox to auto-resize based on orientation change (maybe with a callback function in a workaround)? Thanks in advance to any help. |
Here is a temporary fix that might work for you:
I'll should be handled a little cleaner on the plugin side, so I'll be sure that future updates have this feature. |
hi can you explain how to install and use this fix on my web site ? |
You just put it in a script block, and add it to your document. colorbox and jQuery have to be defined first.
|
maybe, I do something wrong, but it seems to not work for me. you can visit this site : http://test.vincentbourganel.fr/20120623-randonnee-vercors/ |
This is my fault because I left out a ) in my original example code, which is now fixed, but check your javascript console next time. It would have told you of the error and line number. |
hi |
Hi, may be it would be useful. Try this function to initialize colorbox function init_responsive_colorbox( element_id, image_width ){ |
I am really interested in this but looking at all the various code above, I am not getting the big picture. I am not sure if I need to patch the Colorbox script or add additional code. I tried various incarnations of all the code above but cannot get anything to make my Colorbox responsive. Would it possible to add a "responsive" dev branch to the repo? Thanks. |
Hello, Thanks for the great info posted here. This worked for me: ... <script src="/colorbox/jquery.colorbox.js"></script>
Seems like reloading colorbox on resize will do the job so that now it is working fine when resizing on both desktop and my android. |
It's better to put a resizeTimer with it so it doesn't load a million times when making your window smaller: var resizeTimer;
$(window).resize(function(){
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if ($('#cboxOverlay').is(':visible')) {
$.colorbox.load(true);
}
}, 300)
}); |
I normally disable Colorbox on mobile devices. I rather view the original image. Here is a simple solution: |
thanks rick works like a charm! |
When initializing colorbox you can set a maxWidth and maxHeight property: $(SELECTOR).colorbox({maxWidth:'95%', maxHeight:'95%'}); Using a percentage will keep the dimensions "responsive". This should be coupled with RickKuipers's resize handler for full responsive support. |
OK... I don't know what I am doing wrong. I have used var resizeTimer; and even this code without timer, but I always get error "$.colorbox.load is not a function"?! |
I stopped making load a publicly accessible function in a previous release because I forgot anyone was using it. Just use this previous version: https://github.com/jackmoore/colorbox/tree/1.4.4 Working on a larger update that won't be out for a little while, but hope to resolve this issue there so that these workarounds are no longer needed. |
Thanks Jack and Rick, that snippet and reverting to 1.4.4. worked wonderfully. Looking forward to your larger update jack. All the best, love your utility. |
An idea is to compute the size of the video when the page is loaded: <script type="text/javascript">
$(document).ready(function() {
var ytch=30, bw=25, w=640, h=360, maxw=$(window).innerWidth()-2*bw;
if (maxw < w) {
h=Math.floor(h*maxw/w);
w=maxw;
}
$('.yt').colorbox({iframe:true, opacity: 0.8, transition: 'none', innerWidth:w, innerHeight:h+ytch});
});
</script> w and h are the width and the height of the video. The code doesn't resize the frame when the display is rotated or resized dynamically. Here is an example: http://www.qrmii.com. Click on an image in the gallery. |
With latest version of colorbox, colorbox.load is not a function. What is a function to get the resize to work? Thanks! |
@carasmo This was answered a couple comments back: #158 (comment) |
I got this code from stackoverflow. Its done wonders for me. /* Colorbox resize function */
var resizeTimer;
function resizeColorBox()
{
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if (jQuery('#cboxOverlay').is(':visible')) {
jQuery.colorbox.load(true);
}
}, 300)
}
// Resize Colorbox when resizing window or changing mobile device orientation
jQuery(window).resize(resizeColorBox);
window.addEventListener("orientationchange", resizeColorBox, false); |
Ok so like @jackmoore told us we won't be able to use 'load' method. So what I did was change it 'resize' method instead and pass the width and height in percentage. /* Colorbox resize function */
var resizeTimer;
function resizeColorBox()
{
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if (jQuery('#cboxOverlay').is(':visible')) {
jQuery.colorbox.resize({width:'90%', height:'90%'});
}
}, 300)
}
// Resize Colorbox when resizing window or changing mobile device orientation
jQuery(window).resize(resizeColorBox);
window.addEventListener("orientationchange", resizeColorBox, false); |
The above method works for me, however it appears that the colorbox.resize() function does not resize the image element. I am using colorbox with scalePhotos : true and after the resize my images are clipped |
Hey Guys this worked for me... $(".iframe").colorbox({iframe:true, width:"100%", height:"800px"}); the SECOND line is what i added to the code, right below the first line which was already there. The only issue is the clipping of images.... that's not cool.... |
I have created a fix for this based on the previous comments. It involves loading and using the unminified version of colorbox and add some simple code.
With all this done you should be able to use the maxWidth and maxHeight properties and have the colorbox re-size responsively. And it scales the images to on re-size! Keep in mide this is a hack and if you update colorbox files to a newer version you will have to re-apply this fix. But lets hope that there is a good non hack fix for this in the next version. Of course you could re-minify the code in jQuery.colorbox.js if you want at http://jscompress.com/ if you are concerned about file size. Hope this helps |
Hey onfire60 Do you mind me asking where you added the maxWidth and maxHeight properties? Thanks |
Ignore my last post, I used the following:
|
if jackmore read this... another way is to merge pull request #64, to support maxWidth and maxHeight in public resize() function. |
@onfire60 Thanks for your code it works well I'm not so worried about the PC browser maximise, but the smartphone flip is a real deal-breaker. |
shouldn't colorbox automatically detect that it is on a mobile device and if so resize to full screen? |
The Colorbox wasn't created with For example the Reveal modal (see http://foundation.zurb.com/docs/components/reveal.html) from Foundation framework is responsive out of the box. But it's maybe the only thing it does best. On the other hand the Colorbox is feature rich modal window script, which with added support for responsiveness will surely be the leader. |
Hi |
Thanks a lot onfire60 and leanda, your solutions worked for me. I want to customize more of colorbox elements. I'm trying to put the title above the content box (like in prettyphoto) so it can be readable in small screens, and i did it (editing CSS), but when i resize the browser window and the box resizes the title disappears sometimes, and only reappear when i reload the page. Any solutions for this one? |
I guess the colorbox looses it's configuration and only current image is remembered. Through configuration it's been able to get prev/next buttons and it's title. |
appendHTML(); fixed some of it
The strange thing is that the above works fine as long as all your content is inside the #cboxContent div. Everything outside doesn't get brought back in after the reload(). Ideas are welcome here. |
In case anyone is looking for @insis321's solution, it can be found here: https://web.archive.org/web/20140711073257/http://www.templatestock.net/disable-colorbox-on-mobile-devices-tablets/ |
@alfaguru: That is absolutely no solution to the discussed problem. Actually, it's hardly related to this topic. |
@jackmoore |
@SimonSteinberger my only concern was for those like me, coming to this thread and wondering what he had posted. |
@leanda and @onfire60 solution works like a charm. Thanks guys! The problem I am having now is that the image does not automatically resize when you go from portrait to landscape (and vise versa). For example, if you have an image in portrait and then go into landscape (vise versa), the image does not resize but the next image will. Is there a way to resize the current image when you go from portrait to landscape (or vise versa)? |
@francisngo |
The solution with publicMethod.reload() do not work for me with version 1.6.4
and
|
You may just edit CSS file. It really works:
|
thank you very much for Colorbox, very well designed and very useful.
Colorbox seems not to be "responsive" on mobile device:
I wish that Colorbox automatically adjusts itself to the size and orientation of the screen / mobile device : if I change the orientation of the screen / mobile device (ie if I rotate my mobile to adjust horizontal and vertival pictures to the screen size, I wish that Colorbor automatically adjusts itself to the new size / orientation of the screen).
for now, Colorbox only automatically adjusts itself on load of a new picture (in a slideshow for exemple).
colorbox can do that (maybe with a callback function in a workaround) ?
otherwise it would be a great improvement in your plugin (fancybox does it now :http://fancyapps.com/fancybox/)
The text was updated successfully, but these errors were encountered: