On our website we draw a wiggly line using HTML canvas. Before the wiggly line is drawn, I measure the height of the page being loaded using the code at Measure height of element after content is fully loaded and then callback to my drawlines.js script which takes the dimensions of the finished area and draws the wiggly line.
This works fine in Chrome and Firefox but IE9 and 10 seem to intermittently fail to draw the lines on pages such as http://www.petersencreative.com/design. I can't see anything failing in the inspector so I'm at a loss as how to diagnose the problem, let alone fix it.
I appreciate this is a fairly specific problem, but would be really grateful of any pointers.
EDIT: When the code fails in IE, it only ever gets to Alert 0.
function watchForBottomDimension(element, callback) {
var $element, images, loaded;
// Get a jQuery wrapper for `element`
$element = jQuery(element);
alert('0');
// Find the images within it that aren't loaded yet
images = $element.find("img").filter(function(index, img) {
return !img.complete;
});
// Find any?
if (images.length === 0) {
// No, we're done -- call the callback asynchronously for
// consistency with the case below where we have to wait
alert('1');
setTimeout(done, 0);
}
else {
// We're waiting for some images, do that
loaded = 0;
images.load(function() {
// One of them loaded; was it the last one?
if (++loaded === images.length) {
// Yup, we're done
alert('2');
done();
}
});
}
// Handle completion
function done() {
var top, height, bottom;
top = $element.offset().top; // Vert offset of element
height = $element.outerHeight(true); // Height of element
// Offset to bottom of element
bottom = top + height;
// Call the callback with the value
callback(element, bottom);
}
}
This function is within http://www.petersencreative.com/templates/320andup/js/drawlines.js
Pete