clientWidth difference between Chrome and Firefox?

I'm writing a javascript function that waits until all the images are loaded on a webpage and then it modifies their width to fit them into a box. It works like a charm on Chrome (clientWidth is 0 until the image is loaded) but on Firefox it instantly goes some tiny number (in my case 24 instead of ~700) so the actual shrinking part happens before the images is loaded (so it stays at the same size). Any fix ideas ? function shrink() { var images = document.getElementsByTagName("img"); var interval = setInterval(function() { var exit = 0; for (var i = 0; i < images.length; ++i) { if (images[i].clientWidth != 0) exit += 1; } if(exit == images.length ) { clearInterval(interval); for (var i = 0; i < images.length; ++i) { if(images[i].clientWidth > 600) images[i].style.width = 400; } } },100); }

以上就是clientWidth difference between Chrome and Firefox?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏