Reputation: 9
I'm trying to make my Colorbox images responsive and I've achieved that with the below code:
<script type="text/javascript">
// Make ColorBox responsive
jQuery.colorbox.settings.maxWidth = '95%';
jQuery.colorbox.settings.maxHeight = '95%';
// 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);
</script>
but I'm geting the following error:
TypeError: jQuery.colorbox is undefined
jQuery.colorbox.settings.maxWidth = '95%';
Upvotes: 0
Views: 6047
Reputation: 1282
Make sure that you:
Upvotes: 5
Reputation: 10260
Hey your code works fine, you must not be including the script on your page. I simply put the lib on this jsfiddle and your code and it stops throwing the error.
See http://jsfiddle.net/bw9ms/
Please make sure that you have a reference in your code to the jquery lib and colorbox script
like
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js</script>
<script src="../jquery.colorbox.js"></script>
Upvotes: 1
Reputation: 111
You can use the colorbox methods:
$("selector").colorbox({scalePhotos: true, maxWidth: '95%',maxHeight: '95%'});
Upvotes: 0