我正在尝试使我的 Colorbox 图像具有响应能力,我已经通过以下代码实现了这一目标:
<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>
但我收到以下错误:
TypeError: jQuery.colorbox is undefined
jQuery.colorbox.settings.maxWidth = '95%';
最佳答案
确保您:
- 添加了 colorbox javascript 库
- 添加了 jQuery 库,并且已在文档中添加到 colorbox 库之前。
- 没有在文档中两次错误地添加 jQuery 库
关于javascript - TypeError : jQuery. 颜色框未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19446844/