09-02
08
图片自定义缩小
作者:Java伴侣 日期:2009-02-08
代码
onload="ReImgSize()"2008-12-13 15:50<img src="UpFile/s2008516145348.jpg" border="0" onload="ReImgSize()" />
<script language="javascript">
function ReImgSize() {
for (var index = 0; index < document.images.length; index++) {
var widthRestriction = 200;
var heightRestriction = 150;
var rate = document.images[index].width / document.images[index].height;
if (document.images[index].width > widthRestriction) {
document.images[index].width = widthRestriction;
document.images[index].height = widthRestriction / rate;
} else if (document.images[index].height > heightRestriction) {
document.images[index].height = heightRestriction;
document.images[index].width = heightRestriction * rate;
}
}
}
</script>
onload="ReImgSize()"2008-12-13 15:50<img src="UpFile/s2008516145348.jpg" border="0" onload="ReImgSize()" />
<script language="javascript">
function ReImgSize() {
for (var index = 0; index < document.images.length; index++) {
var widthRestriction = 200;
var heightRestriction = 150;
var rate = document.images[index].width / document.images[index].height;
if (document.images[index].width > widthRestriction) {
document.images[index].width = widthRestriction;
document.images[index].height = widthRestriction / rate;
} else if (document.images[index].height > heightRestriction) {
document.images[index].height = heightRestriction;
document.images[index].width = heightRestriction * rate;
}
}
}
</script>
评论: 0 | 引用: 0 | 查看次数: 362
发表评论