So, I have crappy JavaScript for centering images and <object> on the page if they exceed the threshold width. It also checks that some classes have not yet been applied manually.
$('img,object').bind('load', function() { w = $(this).width(); if (w > 400 && !( $(this).hasClass('inlineimage') | $(this).parent().hasClass('inlineimage') )) $(this).css('margin', '10px ' + (parseInt((800-w)/2)-30) +'px'); });
This is terrible, but the meaning of this was initially quite normal. CMS does not make it easy to determine alignment and design it so that it takes a considerable amount of time from other tasks. It works on the client side.
The only problem with this is that JS waits for the whole image to load. Obviously, this means that on slower networks, the page loads, the images begin to load, and after a while the images snap. Ugly.
But the browser seems to know the width of the image as soon as it starts to download it. I would very much like to connect to this event and uncover this visual error.
Of course, if there is a way to approach CSS, I am also open to this.
source share