
这个效果吧(图片请无视)...
<html>
<head>
<title>把图片分成一个个小块</title>
<script>
var img
var canvas
window.onload=function(){
img=document.getElementById("img")
can=document.getElementById("canvas")
canvas=can.getContext(*2d*)
}
var x
var y
//x和y保存上一次鼠标在哪个位置,可以尽量减少canvas的重画次数..其实一般不用减少...但我家256内存伤不起...后面width是你想要的小块宽度,height是长度
function drawImage(_x,_y){//_x,_y为鼠标相对于canvas的坐标
//alert(x+","+y)
var width=400
var height=400
if(!(Math.floor(_x/width)==x&&Math.floor(_y/height)==y)){
canvas.drawImage(img,0,0)
var x=Math.floor(_x/width)
var y=Math.floor(_y/height)
//这里xy代表你的鼠标在哪个区域
canvas.clearRect(0,0,x*width,99999)
canvas.clearRect((x+1)*width,0,99999,99999)
canvas.clearRect(0,0,99999,y*height)
canvas.clearRect(0,(y+1)*height,99999,99999)
}
//整个函数的意思是,当鼠标移到另一个区域时,重新画图片,并且把区域上下左右都清空
}
</script>
</head>
<body>
<img src="009.jpg" height=0 width=0 id="img"/>
<!--载入图片,但不显示,由于我对html不是很熟,就用这个办法了...src后面跟图片的相对路径-->
<canvas height=1000 width=1000 id="canvas" onMouseMove=drawImage(event.offsetX,event.offsetY)>
<!--height对应你图片的高度,width对应宽度,也可设置成自动获取-->
</canvas>
</body>
</html>