600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 网页鼠标滚动实现图片缩放

网页鼠标滚动实现图片缩放

时间:2023-07-05 19:42:09

相关推荐

网页鼠标滚动实现图片缩放

<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 = "点击图片可在新窗口打开";

}

}

}

//-->

</SCRIPT>

<style type=css>

</style>

<div class="test">

<img name="" src="123.jpg" οnlοad="javascript:resizeimg(this,198,235)">

<div>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。