fromMic's blog

在smth web bbs的代码中发现这段脚本,觉得还挺有用的,能让img不再撑开页面:
html:
自动调节img宽度的脚本

js:
var bbsconImg = new Array();

function resizeImg(obj) {
bbsconImg.push(obj);
obj.o_width = obj.width;
var maxWidth = document.body.clientWidth - 40;
if (obj.width > maxWidth) obj.width = maxWidth;
}
function adjustImg() {
var maxWidth = document.body.clientWidth - 40;
for (var i in bbsconImg) {
var obj = bbsconImg[i];
var o_width = obj.o_width;
obj.width = (o_width > maxWidth) ? maxWidth : o_width;
}
}
window.onresize = adjustImg;

相关文章:

  • 2021-08-07
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
相关资源
相似解决方案