首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
限制页面图片大小
编辑
代码正文
双击正文可选择全部
1[代码][javascript]
尝试一下
function limitImage(ImgD){ var areaWidth = 300; //你放置图片区域的宽度。 var areaHeight = 300; //你放置图片区域的高度。 var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= areaWidth/areaHeight){ if(image.width>areaWidth){ ImgD.width=areaWidth; ImgD.height=(image.height*areaWidth)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; }else{ if(image.height>areaHeight){ ImgD.height=areaHeight; ImgD.width=(image.width*areaHeight)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } } }
文明上网理性发言,请遵守新闻评论服务协议
0 条评论
发布评论
全部评论
最新
/
最热
暂无评论
加载更多
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 3 个查询,用时 0.0017600059509277 秒,PHP脚本用时 0.003757 秒,占用内存 0.502 MB,Gzip 已启用