I used the simplest one to use the OnMouseWheel command directly
The code is as follows |
Copy Code |
<script language= "JavaScript" > <!-- Change picture size function Resizepic (thispic) { if (thispic.width>700) thispic.width=700; } stepless scale picture size function Bbimg (o) { var zoom=parseint (o.style.zoom,10) | | 100; ZOOM+=EVENT.WHEELDELTA/12; if (zoom>0) o.style.zoom=zoom+ '% '; return false; } --> </script> |
Example 1
Ie6-8,ff,chrome,opera,safari can be used.
The code is as follows |
Copy Code |
var zooming=function (e) { e=window.event | | E var O=this,data=e.wheeldelta | | E.detail*40,zoom,size; if (!+ ' v1 ') { Zoom = parseint (o.style.zoom) | | 100; Zoom + = DATA/12; if (Zoom > Zooming.min) O.style.zoom = zoom + '% '; } else { Size=o.getattribute ("_zoomsize"). Split (","); Zoom=parseint (O.getattribute ("_zoom")) | | 100; ZOOM+=DATA/12; if (zoom>zooming.min) { O.setattribute ("_zoom", zoom); o.style.width=size[0]*zoom/100+ "px"; o.style.height=size[1]*zoom/100+ "px"; } } }; Zooming.add=function (obj,min) {//The first parameter specifies a picture that can be scaled, min specifies the minimum scale size, default to 50 Zooming.min=min | | 50; obj.onmousewheel=zooming; if (/a/[-1]== ' a ')//if Firefox Obj.addeventlistener ("Dommousescroll", Zooming,false); if (-[1,]) {//if not IE Obj.setattribute ("_zoomsize", obj.offsetwidth+ "," +obj.offsetheight); } }; Window.onload=function () {//Put in onload, otherwise the picture size error cannot be computed in non IE Zooming.add (document.getelementbyidx_x ("TESTIMG1")); } |
Example 2
The code is as follows |
Copy Code |
<script type= "Text/javascript" > function Resizeimg (imgd,iwidth,iheight) { var image=new image (); IMAGE.SRC=IMGD.SRC; if (image.width>0 && image.height>0) { 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+ "X" +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+ "X" +image.height; } imgd.style.cursor= "Pointer"; Change the mouse pointer if (Navigator.userAgent.toLowerCase (). IndexOf ("ie") >-1) {//Judging browser, if it is IE Imgd.title = "Please use the mouse wheel to zoom picture"; Imgd.onmousewheel = function img_zoom ()//Wheel Zoom { var zoom = parseint (This.style.zoom, 10) | | 100; Zoom + = EVENT.WHEELDELTA/12; if (zoom> 0) this.style.zoom = zoom + "%"; return false; } } } } </script> <body> Example:
</body> |