最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
js 加载时自动调整图片大小
时间:2018-08-22 编辑:猪哥 来源:一聚教程网
// 方法:setSelectReadOnly 用于设定极select控件ReadOnly, // 这个一个模拟只读不是真的只读 // 使用了onbeforeactivate,onfocus,onmouseover,onmouseout事件 // 示例:< img src='img.jpg' onload='ImgAutoSize(ImgD,FitWidth,FitHeight)' > ; // create by sl // --------------------------------------------------- function ImgAutoSize(imgD,FitWidth,FitHeight) { var image1=new Image(); image1.onload = function () { if(this.width>0 && this.height>0) { if(this.width/this.height>= FitWidth/FitHeight) { if(this.width>FitWidth) { imgD.width=FitWidth; imgD.height=(this.height*FitWidth)/this.width; } else { imgD.width=this.width; imgD.height=this.height; } } else { if(this.height>FitHeight) { imgD.height=FitHeight; imgD.width=(this.width*FitHeight)/this.height; } else { imgD.width=this.width; imgD.height=this.height; } } } image1 = null; } image1.src=imgD.src; imgD.style.cursor = 'hand'; imgD.onclick= function(){openWin(this.src,'imgphoto',600,400)}; imgD.title = "点击在新窗口中查看原图"; }
-
上一个: JS中数组与对象的遍历方法实例小结
-
下一个: LayUI表格批量删除方法
相关文章
- js实现音乐播放器代码展示 10-12
- js实现图片查看器代码展示 10-12
- JS中switch的四种写法介绍 10-12
- js实现新闻轮播效果教程 10-11
- JS实现简单的图片切换功能教程 10-11
- js实现下拉刷新和上拉加载解析 09-28