Hi i'm trying to display different image in different part of my site, but i need to display a default image if image doesn't exist.
here is my code: the problem is to check the img width but is alway
jQuery(document).ready(function () {
var $pathname = window.location.pathname;
$item = 'http://www.lotus-nascita.it/images/headers-hover/corsi-preparto.jpg';
if ($pathname == '/') {
$pathname = $pathname + 'home';
$item = 'http://www.lotus-nascita.it/images/headers-hover' + $pathname + '.jpg';
}
var img = new Image();
img.onload = function () {}
img.src = $item;
if (img.height != 0) {
$item = 'http://www.lotus-nascita.it/images/headers-hover' + $pathname + '.jpg';
}
jQuery('#header').fadeOut('fast', function () {
jQuery('#header').css({
"background": 'url("' + $item + '")'
});
jQuery('#header').fadeIn('slow');
});
});