FitFill Image

/* Fill an image (ref) in its parent or fit if 2nd param is true. */ function imgsizein(ref,fit){ fit = typeof fit !== 'undefined' ? fit : false; var myImage = ref; myImage.css({ 'position' : 'absolute', 'max-width' : 'none', 'max-height' : 'none' }); var w_width = ref.parent().width(); var w_height = ref.parent().height(); var i_width = myImage.width(); var i_height = myImage.height(); var ratio_src = w_width/w_height; var ratio_img = i_width/i_height; if(ratio_img>ratio_src){ if (fit==true) { myImage.css('width','94%'); myImage.css('height','auto'); } else { myImage.css('height','104%'); myImage.css('width','auto'); } } else { if (fit==true) { myImage.css('height','94%'); myImage.css('width','auto'); } else { myImage.css('width','104%'); myImage.css('height','auto'); } } i_width = myImage.width(); i_height = myImage.height(); if (fit==true) { posLeft = Math.round((w_width-i_width)/2); } else { posLeft = Math.round((w_width-i_width)/2-(w_width/100)); } myImage.css('left',posLeft); posTop = Math.round((w_height-i_height)/2); myImage.css('top',posTop); ref.parent().css('overflow','hidden'); }
Fill an image (ref) in its parent
or fit if 2nd param is true.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.