$(".pics").each(function(){ var group = $(this).attr("group"); $(this).find(".thumbnail > img").colorbox({ "href": function() { return $(this).attr("full") }, "title": function() { return $(this).attr("title") }, "rel": group, "current": "{current}/{total}", "maxWidth": "90%", "maxHeight": "90%", }); }); var resizeTimer; $(window).resize(function(){ if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout(function() { if ($('#cboxOverlay').is(':visible')) { $.colorbox.load(true); } }, 300) });