
求实现自动生成图片缩略图的JS代码
要求:不管原图大小多大,统一缩小成指定宽度,高度则按照宽度缩小的比例自适应... 例如:原图分辨率是1000(weight)x600(Height);假设固定宽...
要求:不管原图大小多大,统一缩小成指定宽度,高度则按照宽度缩小的比例自适应... 例如:原图分辨率是1000(weight) x 600(Height);假设固定宽度为200,高度自动缩小相同比例,最后缩略图尺寸为:200 x 120.
展开
1个回答
展开全部
1.将以下JS代码放在页面顶部,或者放在要调整图片的前面
<script type="text/javascript">
function ReSizePic(ThisPic){
var RePicWidth = 200; //这里修改为您想显示的宽度值
//============以下代码请勿修改==================================
var TrueWidth = ThisPic.width; //图片实际宽度
var TrueHeight = ThisPic.height; //图片实际高度
var Multiple = TrueWidth / RePicWidth; //图片缩小(放大)的倍数
ThisPic.width = RePicWidth; //图片显示的可视宽度
ThisPic.height = TrueHeight / Multiple; //图片显示的可视高度
}
</script>
===========================================================================
2.在所有要调整图片里加入代码:onload="ReSizePic(this);"
如:<img src="http://img208.poco.cn/mypoco/myphoto/20110702/19/56945956201107021915139206804535901_001.jpg" onload="ReSizePic(this);">
<script type="text/javascript">
function ReSizePic(ThisPic){
var RePicWidth = 200; //这里修改为您想显示的宽度值
//============以下代码请勿修改==================================
var TrueWidth = ThisPic.width; //图片实际宽度
var TrueHeight = ThisPic.height; //图片实际高度
var Multiple = TrueWidth / RePicWidth; //图片缩小(放大)的倍数
ThisPic.width = RePicWidth; //图片显示的可视宽度
ThisPic.height = TrueHeight / Multiple; //图片显示的可视高度
}
</script>
===========================================================================
2.在所有要调整图片里加入代码:onload="ReSizePic(this);"
如:<img src="http://img208.poco.cn/mypoco/myphoto/20110702/19/56945956201107021915139206804535901_001.jpg" onload="ReSizePic(this);">

2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询