javascript - TypeError: jQuery.colorbox is undefined - Stack Overflow

I'm trying to make my Colorbox images responsive and I've achieved that with the below code:&

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%';

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%';
Share Improve this question edited Oct 18, 2013 at 10:19 Qantas 94 Heavy 16k31 gold badges72 silver badges88 bronze badges asked Oct 18, 2013 at 10:00 Rumen FidanovRumen Fidanov 91 silver badge2 bronze badges 2
  • Have you included the colourbox js file in your page? – Rory McCrossan Commented Oct 18, 2013 at 10:01
  • Do you import framework in your script? – zur4ik Commented Oct 18, 2013 at 10:01
Add a ment  | 

3 Answers 3

Reset to default 5

Make sure that you:

  1. Added the colorbox javascript library
  2. Added the jQuery library and it has been added before the colorbox library in the document.
  3. Haven't mistakenly added jQuery library twice in the document

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/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./ajax/libs/jquery/1.10.2/jquery.min.js</script>
    <script src="../jquery.colorbox.js"></script>

You can use the colorbox methods:

$("selector").colorbox({scalePhotos: true, maxWidth: '95%',maxHeight: '95%'});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744596725a4582933.html

相关推荐

  • javascript - TypeError: jQuery.colorbox is undefined - Stack Overflow

    I'm trying to make my Colorbox images responsive and I've achieved that with the below code:&

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信