js 图片缩放(按比例)控制代码_图象特效

缩放代码:

复制代码 代码如下:

缩放代码:
<script type="text/javascript">
//图片按比例缩放
var flag = false;
function DrawImage(ImgD, iwidth, iheight) {
//参数(图片,允许的宽度,允许的高度)
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
flag = true;
if (image.width / image.height >= iwidth / iheight) {
if (image.width > iwidth) {
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
ImgD.alt = image.width + "×" + image.height;
}
else {
if (image.height > iheight) {
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
ImgD.alt = image.width + "×" + image.height;
}
}
}
</script>
页面代码:
<img onload="javascript:DrawImage(this,89,63)" src=https://yunqi-tech.oss-cn-hangzhou.aliyuncs.com/logo.gif width="89" height="63" border="0" />
觉得不错的发个言!

页面代码:
1. <img onload="javascript:DrawImage(this,89,63)" src=https://yunqi-tech.oss-cn-hangzhou.aliyuncs.com/baidu_logo.gif width="89" height="63" border="0" />
觉得不错的发个言!

时间: 2024-09-20 05:36:59

js 图片缩放(按比例)控制代码_图象特效的相关文章

常见JS效果之图片减速度滚动实现代码_图象特效

复制代码 代码如下: <!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title>图片减速度滚动(by rentj1@163.com;)</title> <style> ul{ margin:0; padding:0} ul{ list-style:none;} body{font:12px/1.2 "宋体"; } .

javascript 图片放大缩小功能实现代码_图象特效

JS图片浏览组件PhotoLook的公开属性方法介绍和进阶实例代码_图象特效

属性 speed :设置图片切换的速度 width:组件的宽度 height:组件的高度 cellStructures:可设置效果矩阵的行列例如{row:8,col:8}注意,这个行列要和效果矩阵switchTable的行列对应 方法 init():初始化 addswitchTable(switchTable):添加效果矩阵 add(url):添加图片 addswitchMethod(func,type):添加切换方法(例如淡出,滑出),现在功能未完整,type只能填"show"一个值

图片上传即时显示缩略图的js代码_图象特效

<script language="javascript" type="text/javascript"> var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg']; var preivew = function(file, container){ try{ var pic = new Picture(file, container); }catch(e){ alert(e); } } //缩略图类定义 va

javascript椭圆旋转相册实现代码_图象特效

功能说明: 1.支持自动和手动两种模式:自动模式下自动旋转展示,手动模式下通过鼠标选择当前图片,或通过提供的接口选择上一张/下一张图片. 2.可自行添加旋转的缓动模式,默认模式为:匀速,先快后慢,先慢后快. 3.可自定义旋转轨迹的宽和高. 4.支持IE6 7 8 9 10 firefox chrome等浏览器. 效果预览: 实现原理: 根据对图片在椭圆轨迹上的运动,动态改变缩放大小,实现立体的视觉效果. 代码分析: 复制代码 代码如下: init:function(id,options){ va

关于图片按比例自适应缩放的js代码_图象特效

如下图. 瞄了一下,居中可以用 text-align:center; 来实现.而按比例缩放,利用预设 <img /> 的 width .height 属性解决不了.因为用户图片可能是很长的,也可能是很宽的.在线上想了一下他们的关系,按条件来判断是这样的: 复制代码 代码如下: if(实际宽度 > 预览最大宽度) { 缩放宽度 = 预览最大宽度 } if(实际高度 > 预览最大高度) { 缩放高度 = 预览最大高度 } 但是这样会有问题,比如当宽度和高度都被缩放,如果缩放比较不同,图

js 图片等比例缩放代码_图象特效

复制代码 代码如下: var scaleImage = function(o, w, h){ var img = new Image(); img.src = o.src; if(img.width >0 && img.height>0) { if(img.width/img.height >= w/h) { if(img.width > w) { o.width = w; o.height = (img.height*w) / img.width; } else

js 图片缩放特效代码_图象特效

鼠标滚轮放大图片

JS 图片缩放效果代码_图象特效

复制代码 代码如下: <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <TITLE>onMouseWheel</TITLE> <SCRIPT> var count = 10; function Picture() { count = Counting(count); Resize