标题 | JS重置图片的高宽 |
范文 | <script type="text/javascript"> //正文图片内容溢出处理 function ReDrawImage(obj) { var boxwidth = 680; // $(obj).width() - 20; $(obj + " img").each(function () { var imgwidth = $(this).width(); var imgheight = $(this).height(); if (imgwidth > boxwidth) { $(this).width(boxwidth); $(this).height(boxwidth / imgwidth * imgheight); } }) $(obj + " table table").each(function () { if ($(this).width() > boxwidth) { $(this).width(boxwidth); $(this).height(boxwidth / $(this).width() * $(this).height()); } }) $(obj + " tr tr").each(function () { var trimg = $(this).find('img'); if (trimg.length > 1) { var trimgwidth = (boxwidth / trimg.length); trimg.each(function () { if ($(this).width() > trimgwidth) { $(this).width(trimgwidth); $(this).height(trimgwidth / $(this).width() * $(this).height()); } }); } }) } $(window).load(function () { ReDrawImage(".newpic");//可以是ID,或者类 (要设置的范围) }); </script> |
随便看 |
|
在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。