ok i kind of managed, if anyone interested, i did it like this: $('a.jqmodal').bind('click',function(){ imgPreloader = new Image(); //var mOffset = $('#modalWindow').show().offset();
//$.log("mWidth =" + mWidth); //$.log("mHeight =" + mHeight); imgPreloader.onload = function(){ imgPreloader.onload = null; var imageWidth = imgPreloader.width; var imageHeight = imgPreloader.height; var w = $(window).width() - 100; var h = $(window).height() - 100; $.log('screen width =' +w); $.log('screen height =' +h); if (imageWidth > w) { imageHeight = imageHeight * (w / imageWidth); imageWidth = w; if (imageHeight > h) { imageWidth = imageWidth * (h / imageHeight); imageHeight = h; } } else if (imageHeight > h) { imageWidth = imageWidth * (h / imageHeight); imageHeight = h; if (imageWidth > w) { imageHeight = imageHeight * (w / imageWidth); imageWidth = w; } } var mWinWidth = parseFloat(imageWidth + 30); var mWinHeight = parseFloat(imageHeight + 60); var mWinTop = parseFloat((h- imageHeight))/2; var mWinLeft = parseFloat((w-imageWidth))/2; $.log('mWinTop =' +mWinTop); $.log('mWinLeft =' + mWinLeft); $('.jqmWindow').css({ margin: 0, width: mWinWidth + 'px', height: mWinHeight+'px', top: mWinTop+'px', left: mWinLeft + 'px' }); $img = "<img id='TB_Image' src='" + this.src + "' width='" + imageWidth + "' height='" + imageHeight + "' alt=''/>"; $('#modalTitle').html(this.title); $('#modalContent').html($img); $('#modalWindow').jqmShow(); } imgPreloader.src = $(this).attr("href"); imgPreloader.title = $(this).attr("title"); return false; });