jQuery innerWidth in Chrome with invisible elements -


i having odd problem jquery 1.5.2 in chrome.

i have code looks following

$("img").each(function () {     if (this.complete) {         imageonload.call(this);     } else {         $(this).bind("load", imageonload);     } });  function imageonload () {   var $this = $(this);    foo($this);  }  function foo ($img) {   var width = $img.innerwidth();   var height = $img.innerheight(); }

keel in mind simplified question.

the above works great in cases. problem when $img(":visible") == false, chrome returning 0 innerwidth , innerheight. need take padding account, hence inner functions.

what best way go handling situation? using

function foo ($img) {     var width;     var height;      if ($img.is(":visible")) {         width = $img.innerwidth();         height = $img.innerheight();     } else {         var img = $img[0];         var pt = parseint(img.style.paddingtop);         var pb = parseint(img.style.paddingbottom);         var pl = parseint(img.style.paddingleft);         var pr = parseint(img.style.paddingright);          width = img.width + pl + pr;         height = img.height + pt + pb;     } }

but know rife problems. can't quite unravel how jquery calculates individual padding, suspect adapting improve else section of hack.

is there better solution or workaround getting innerwidth , innerheight when $img(":visible") == false?

thanks.

addendum:

as noted in comment below, solution not simple making image visible, calculating, , hiding. if in parent chain not visible, problem happens. in addition, few things can trigger problem.

height , width calculate 0 in both chrome , firefox when image or descendent has display:none. chrome, apparently not firefox, when image masked off because descendent has overflow:hidden. going try see how works in safari later weekend.

what setting image visible, take width/height , make image invisible again? user shouldn't see appear/disappear, unless image 15mb shitload :).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -