<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片放大缩小</title>
<style type="text/css">
*{
margin:0; padding:0;
}
body {
width:100%; height:100%; overflow:auto;
}
#img {
display:block;
width:20%;
margin:20px auto;
cursor:-webkit-zoom-in;
cursor:-moz-zoom-in;
border:4px solid #ccc;
}
</style>
<script src="./jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var img=$("#img");
var i=0;
img.bind('DOMMouseScroll mousewheel function(e) {
var ev=window.event||e;//处理浏览器兼容性问题
var scrollUnit=Math.max(-1,Math.min(1,(ev.wheelDelta||-ev.detail)));
var newWith=Math.max(100,Math.min(1600,parseInt(img.css("width"))+(30*scrollUnit)))+"px";
img.css("width",newWith);
console.log(i++);
console.log(img.css("width"));