<SCRIPT LANGUAGE="JavaScript">
<!--
//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight) {
var p_w_picpath=new Image();
p_w_picpath.src=ImgD.src;
if(p_w_picpath.width>0 && p_w_picpath.height>0){
if(p_w_picpath.width/p_w_picpath.height>= iwidth/iheight){
if(p_w_picpath.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(p_w_picpath.height*iwidth)/p_w_picpath.width;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
else{
if(p_w_picpath.height>iheight){
ImgD.height=iheight;
ImgD.width=(p_w_picpath.width*iheight)/p_w_picpath.height;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
ImgD.style.cursor= "pointer"; //改变鼠标指针
ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
ImgD.title = "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
ImgD. = function img_zoom() //滚轮缩放
{
var zoom = parseInt(this.style.zoom, 10) || 100;
zoom += event.wheelDelta / 12;
if (zoom> 0) this.style.zoom = zoom + "%";
return false;
}
} else { //如果不是IE
ImgD.title = "点击图片可在新窗口打开";
}
}
}
<!--
//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight) {
var p_w_picpath=new Image();
p_w_picpath.src=ImgD.src;
if(p_w_picpath.width>0 && p_w_picpath.height>0){
if(p_w_picpath.width/p_w_picpath.height>= iwidth/iheight){
if(p_w_picpath.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(p_w_picpath.height*iwidth)/p_w_picpath.width;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
else{
if(p_w_picpath.height>iheight){
ImgD.height=iheight;
ImgD.width=(p_w_picpath.width*iheight)/p_w_picpath.height;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
ImgD.style.cursor= "pointer"; //改变鼠标指针
ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
ImgD.title = "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
ImgD. = function img_zoom() //滚轮缩放
{
var zoom = parseInt(this.style.zoom, 10) || 100;
zoom += event.wheelDelta / 12;
if (zoom> 0) this.style.zoom = zoom + "%";
return false;
}
} else { //如果不是IE
ImgD.title = "点击图片可在新窗口打开";
}
}
}
//-->
</SCRIPT>
<style type=css>
</style>
<div class="test">
<img name="" src="123.jpg" οnlοad="javascript:resizeimg(this,198,235)">
<div>
转载于:https://blog.51cto.com/bhanv/287983