图片缩放效果--IE和火狐兼容模式

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
 <meta http-equiv = "Content-Type" content="text/html;charset=gb2312"/>
  <title> 图片放大缩小</title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
<style>
  .one{width:90px;height:100px}
  </style>
<script language="javascript">
window.onload=function(){
	var img1 = document.getElementsByTagName("img")[0];
	//火狐和IE兼容的获得元素属性
	/*function getsize(obj,att){
		if(document.all){
			return obj.currentStyle[att];
		}
		else{
			return getComputedStyle(obj,att)[att];
		}
	}
	alert(getsize(img1,"width"));
	*/
	//火狐和IE兼容的获得鼠标滚轮信息
if(img1.addEventListener){
	img1.onmousewheel = scrollfun;
	img1.addEventListener("DOMMouseScroll",scrollfun,false);
	}
	function scrollfun (e){
		var ev= e || window.event;//兼容分别为IE和火狐
		var num=ev.wheelDelta||ev.detail;//兼容分别为IE和火狐
		//alert(num);
		if((num== -3 || num ==120) && img1.offsetWidth < 900){
			img1.style.width = (img1.offsetWidth)*1.2 +"px";
			img1.style.height = (img1.offsetHeight)*1.2 +"px";
		}
		else if((num ==3 || num ==-120) && img1.offsetWidth >60){
			img1.style.width =(img1.offsetWidth)/1.2 + "px";
			img1.style.height = (img1.offsetHeight)/1.2+ "px";
		}
		}
}

</script>
 </head>
<!--"D:/Myfile/图片/1.jpg"-->
 <body>
  <img src="file:///D|/1.jpg" class="one"/>
 </body>
</html>

  

posted @ 2012-10-16 12:15  龙杉老师  阅读(1012)  评论(2编辑  收藏  举报